sql: 表结构查询

王朝学院·作者佚名  2016-05-25
窄屏简体版  字體: 小  |  中  |  大  |  超大  

sql: 表结构查询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';

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航