sql server 2005:
1 --SQL SERVER 2005 生成代碼需要知道的SQL語句2 use LibrarySystem3 --查詢當前數據庫所有表和其的主鍵字段,字段類型,長度,是否為空值4 SELECT d.name as 'TableName',a.name as 'FieldName',b.name as 'TypeName',a.length as 'Length',a.isnullable as 'IS_NULL' FROM syscolumns a, systypes b,sysobjects d ,INFORMATION_SCHEMA.KEY_COLUMN_USAGE c WHERE a.xtype=b.xusertype and a.id=d.id and d.xtype='U' and c.TABLE_NAME = d.name and c.COLUMN_NAME=a.name5 --獲取BookKindList表結構里面的字段名, 類型,長度6 SELECT c.name as FieldName,t.name as FieldType, c.length as FieldLength FROM SYSCOLUMNS c inner join systypes t on c.xusertype=t.xusertype WHERE c.ID = OBJECT_ID('BookKindList')7 --
MySQL 6.7
1 #數據庫MySQL 6.7 2 use sakila; 3 #查詢表名 4 show tables; 5 # 6 SELECT TABLE_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='sakila'; 7 8 select column_name from information_schema.columns where table_schema='sakila' and table_name='actor'; 9 #表結構 字段名, 類型,長度10 select * from information_schema.columns where table_schema='sakila' and table_name='actor';
#所有表的主鍵select * from information_schema.columns where table_schema='attend' and column_key='PRI';
PostgreSQL 8.4,9.3
1 --查詢結構PostgreSQL 8.4,9.32 SELECT * FROM information_schema.columns;3 --查詢數據庫的建成立的表結構4 SELECT * FROM information_schema.columns where table_catalog='geovindu' and table_schema='public';
新聞熱點
疑難解答