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


当前回答

Oracle (PL/SQL)

SELECT column_name
FROM user_tab_cols
WHERE table_name = 'myTableName'

MySQL

SHOW COLUMNS FROM table_name

其他回答

Oracle (PL/SQL)

SELECT column_name
FROM user_tab_cols
WHERE table_name = 'myTableName'

MySQL

SHOW COLUMNS FROM table_name

只是对SQL Server中的其他选项做了一点小小的修正(模式前缀变得越来越重要了!):

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

只是我的代码

SQL Server

sp_help tablename

对于MySQL,使用:

DESCRIBE name_of_table;

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