你的位置:首页 > 数据库

[数据库]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';

 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';