使用于SQL SERVER 2008----查詢所有數據庫名
1 SELECT Name FROM Master..SysDatabases ORDER BY Name
----查詢某數據庫中的所有表名
1 SELECT Name FROM 數據庫名..SysObjects Where XType='U' ORDER BY Name
----查詢數據表的字段信息
1 select 2 a.name as FieldName, -- 字段名 3 a.isnullable, -- 是否可為空 4 b.Value as FieldDesc, -- 字段說明 5 c.name as FieldType, -- 數據類型 6 COLUMNPROPERTY(a.id,a.name,'IsIdentity') as isidentity, --是否標識列 7 PK=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in ( 8 SELECT name FROM sysindexes WHERE indid in( 9 SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid10 ))) then 'true' else 'false' end --是否主鍵11 from SysColumns a left join12 sysproperties b on a.id=b.id and a.colid=b.smallid left join systypes c on a.xusertype=c.xusertype13 where a.id=Object_Id('數據表名')
新聞熱點
疑難解答