1. 程式人生 > >取得指定表的欄位定義

取得指定表的欄位定義

MYSQL中取得指定表的欄位定義(假設表名為mytable):


DESCRIBE mytable

MYSQLServer中取得指定表的欄位定義(假設表名為mytable):


SELECT syscols.name as COLUMN_NAME,st.name as DATA_TYPE,syscomm.text as DATA_DEFAULT,syscols.isnullable as NULLABLE FROM syscolumns syscols left join systypes st on syscols.xusertype=st.xusertype left join syscomments syscomm on syscols.cdefault=syscomm.id where syscols.id=OBJECT_ID(N"mytable") order by syscols.id,syscols.colorder 

Oracle中的all_tab_columns表是系統中所有表的欄位定義,其中TABLE_NAME欄位為表名,因此取得指定表的欄位定義(假設表名為mytable):


select COLUMN_NAME,DATA_TYPE,DATA_DEFAULT,NULLABLE from all_tab_columns where TABLE_NAME ="MYTABLE"

DB2中的syscat.columns表是系統中所有表的欄位定義,其中TABNAME欄位為表名,因此取得指定表的欄位定義(假設表名為mytable):


select COLNAME as COLUMN_NAME, TYPENAME as DATA_TYPE,DEFAULT as DATA_DEFAULT,NULLS as NULLABLE from syscat.columns where TABNAME="MYTABLE"