如何列出表格中的所有列?

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

对于MySQL / Oracle,使用:

DESCRIBE name_of_table; 

对于Oracle(PL / SQL)

 SELECT column_name FROM user_tab_cols WHERE table_name = 'myTableName' 

对于MySQL

 SHOW COLUMNS FROM table_name 

对于MS SQL Server:

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

我知道这是晚了,但我使用(对于甲骨文:

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

(5年以上,PostgreSQL荣誉,王国最先进的DDBB)

在PostgreSQL中:

 \d table_name 

或者,使用SQL:

 select column_name, data_type, character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name = 'table_name'; 

SQL Server

 SELECT c.name FROM sys.objects o INNER JOIN sys.columns c ON c.object_id = o.object_id AND o.name = '[Table Name]' 

要么

 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '[Table Name]' 

第二种方法是ANSI标准,因此应该适用于所有符合ANSI标准的数据库。

MS SQL Server:

sp_columns [tablename]

Microsoft SQL Server Management Studio 2008 R2:

在查询编辑器中,如果突出显示表名(ex dbo.MyTable)的文本并按下ALT + F1 ,则会得到列名,types,长度等列表。

ALT + F1突出显示dbo.MyTable相当于根据这个站点运行EXEC sp_help 'dbo.MyTable'

我不能得到查询INFORMATION_SCHEMA.COLUMNS工作的变化,所以我用它来代替。

对于SQL Server

 sp_help tablename 

SQL Server

要列出数据库的所有用户定义表:

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

要列出表格的所有列:

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

对SQL Server中的其他人稍作修改(模式前缀变得越来越重要!):

 SELECT name FROM sys.columns WHERE [object_id] = OBJECT_ID('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 

只是我的代码