对于各种流行的数据库系统,如何列出表中的所有列?
当前回答
SQL Server
sp_help tablename
其他回答
只是对SQL Server中的其他选项做了一点小小的修正(模式前缀变得越来越重要了!):
SELECT name
FROM sys.columns
WHERE [object_id] = OBJECT_ID(N'dbo.tablename');
(5年后,为了王国最先进的DDBB PostgreSQL的荣誉)
在PostgreSQL:
\d table_name
或者,使用SQL:
select column_name, data_type, character_maximum_length
from INFORMATION_SCHEMA.COLUMNS
where table_name = 'table_name';
对于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
例子:
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
只是我的代码