首页 > 开发 > 综合 > 正文

sql: 表结构查询

2024-07-21 02:47:35
字体:
来源:转载
供稿:网友
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';


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表