database 如何获取sybase表列名及其数据类型和排序依据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28936131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:54:05  来源:igfitidea点击:

How to get sybase table column name and its datatype and order by?

databasesybase

提问by A.Goutam

There are multiple table in my sybase database. I want to know the column name and datatype of a given table like (myOrder table). How can I do this? Below script I found on stackoverflow From a Sybase Database, how I can get table description ( field names and types)? . But this gives me exception syscolumns is ambiguous? The script is below that I used for this.

我的 sybase 数据库中有多个表。我想知道给定表(如(myOrder 表))的列名和数据类型。我怎样才能做到这一点?下面是我在 stackoverflow 上从 Sybase 数据库中找到的脚本,如何获取表描述(字段名称和类型)?. 但这给了我例外syscolumns is ambiguous?脚本在我用于此的下面。

SELECT sc.* 
FROM syscolumns sc
INNER JOIN sysobjects so ON sc.id = so.id
WHERE so.name = 'my_table_name'

回答by www

To extract types I am using such query:

要提取类型,我正在使用这样的查询:

SELECT syscolumns.name, systypes.name FROM sysobjects 
JOIN syscolumns ON sysobjects.id = syscolumns.id
JOIN systypes ON systypes.type = syscolumns.type AND systypes.usertype = syscolumns.usertype
WHERE sysobjects.name LIKE 'my_table' 

回答by Sahil Bhatia

To get column names, data types and a lot more info for a table in Sybase, use the following query.

要在 Sybase 中获取表的列名、数据类型和更多信息,请使用以下查询。

Select * from systabcol
key join systab
 where table_name = 'your_table_name'

回答by hui chen

You can use built-in procedure sp_columns. It will return all the table metadata including column name, data type, column length etc. for a given table.

您可以使用内置过程 sp_columns。它将返回给定表的所有表元数据,包括列名、数据类型、列长度等。

sp_columns table_name

回答by mega

Sybase Central gets the columns like this:

Sybase Central 获取这样的列:

select
    col.name,
    isnull(xt.xtname, isnull(get_xtypename(col.xtype, col.xdbid), t.name))
from
    syscolumns col
join
    sysobjects obj
on
    col.id = obj.id
left outer join
    systypes t
on
    col.usertype = t.usertype
left outer join
    sysxtypes xt
on
    col.xtype = xt.xtid
where
    obj.name like 'sysobjects'
order by
    col.colid

回答by AlienFromCA

Just to add a hopefully useful addition here, I use Sybase's SQL Anywhere 12, so, the syscolumns object(view) does not hold the same information as other versions of Sybase, and therefore requires joining on named information. However, this consolidated view, as it is called, is almost perfectly capable by itself (see it's documentation here).

只是为了在这里添加一个希望有用的补充,我使用 Sybase 的 SQL Anywhere 12,因此,syscolumns 对象(视图)与其他版本的 Sybase 不保存相同的信息,因此需要加入命名信息。然而,正如所称的那样,这种整合的视图本身几乎是完全有能力的(请参阅此处的文档)。

We in fact use it for checking changes to columns across all tables, as a QA tool, similar to this:

我们实际上使用它来检查所有表中列的更改,作为 QA 工具,类似于:

Select * 
    From sys.syscolumns 
    Where (cname Like '%trk%' Or cname Like '%track%') 
    And cname not like '%ontrack%' 
    Order By tname;