sql代码:select database select all table,供大家学习参考。
复制代码 代码如下:
---表中的主鍵
select [name],'tablekey'= (select top 1 COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where TABLE_NAME = sysobjects.name) from sysobjects where type='U'
--所有表
select * from sysobjects where type='U'
--所有表的主鍵 COLUMN_NAME
select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
--数据类型
select * from systypes
--所有列
select * FROM syscolumns
--所有表的數據類型,長度
SELECT d.name TableName,a.name FieldName,b.name TypeName,a.length Length,a.isnullable IS_NULL --INTO #t
FROM syscolumns a, systypes b,sysobjects d
WHERE a.xtype=b.xusertype and a.id=d.id and d.xtype='U'
---所有表的主鍵
SELECT d.name as 'TableName',a.name as 'FieldName',b.name as 'TypeName',a.length as 'Length',a.isnullable as 'IS_NULL' --INTO #t
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.name