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


当前回答

对于mssql Server:

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

其他回答

Oracle (PL/SQL)

SELECT column_name
FROM user_tab_cols
WHERE table_name = 'myTableName'

MySQL

SHOW COLUMNS FROM table_name

对于MySQL,使用:

DESCRIBE name_of_table;

这也适用于Oracle,只要你使用SQL*Plus,或Oracle的SQL Developer。

例子:

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

只是我的代码

在MS SQL Server中调用以下代码:

sp_columns [tablename]

SQL Server

sp_help tablename