对于各种流行的数据库系统,如何列出表中的所有列?


当前回答

我知道已经很晚了,但是我在Oracle上使用这个命令:

select column_name,data_type,data_length from all_tab_columns where TABLE_NAME = 'xxxx' AND OWNER ='xxxxxxxxxx'

其他回答

只是对SQL Server中的其他选项做了一点小小的修正(模式前缀变得越来越重要了!):

SELECT name
  FROM sys.columns 
  WHERE [object_id] = OBJECT_ID(N'dbo.tablename');

例子:

select Table_name as [Table] , column_name as [Column] , Table_catalog as [Database], table_schema as [Schema]  from information_schema.columns
where table_schema = 'dbo'
order by Table_name,COLUMN_NAME

只是我的代码

SQL Server

使用实例列出数据库中所有用户定义的表。

use [databasename]
select name from sysobjects where type = 'u'

列出一个表的所有列:

use [databasename]
select name from syscolumns where id=object_id('tablename')

对于mssql Server:

select COLUMN_NAME from information_schema.columns where table_name = 'tableName'

我知道已经很晚了,但是我在Oracle上使用这个命令:

select column_name,data_type,data_length from all_tab_columns where TABLE_NAME = 'xxxx' AND OWNER ='xxxxxxxxxx'