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


当前回答

SQL Server

sp_help tablename

其他回答

Microsoft SQL Server Management Studio 2008 R2:

在查询编辑器中,如果突出显示表名的文本(例如dbo.MyTable)并点击ALT+F1,您将得到列名、类型、长度等的列表。

ALT+F1,同时高亮dbo。MyTable相当于运行EXEC sp_help 'dbo。MyTable”

我无法获得查询INFORMATION_SCHEMA的变体。列来工作,所以我用这个代替。

例子:

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

只是我的代码

对于mssql Server:

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

SQL Server

sp_help tablename

Oracle (PL/SQL)

SELECT column_name
FROM user_tab_cols
WHERE table_name = 'myTableName'

MySQL

SHOW COLUMNS FROM table_name