对于各种流行的数据库系统,如何列出表中的所有列?
当前回答
例子:
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
使用实例列出数据库中所有用户定义的表。
use [databasename]
select name from sysobjects where type = 'u'
列出一个表的所有列:
use [databasename]
select name from syscolumns where id=object_id('tablename')
SQL Server
sp_help tablename
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'
or
SELECT
COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'Table_Name'
第二种方法是ANSI标准,因此应该适用于所有符合ANSI标准的数据库。
Oracle (PL/SQL)
SELECT column_name
FROM user_tab_cols
WHERE table_name = 'myTableName'
MySQL
SHOW COLUMNS FROM table_name