使用于SQL SERVER 2008----查詢(xún)所有數(shù)據(jù)庫(kù)名
1 SELECT Name FROM Master..SysDatabases ORDER BY Name
----查詢(xún)某數(shù)據(jù)庫(kù)中的所有表名
1 SELECT Name FROM 數(shù)據(jù)庫(kù)名..SysObjects Where XType='U' ORDER BY Name
----查詢(xún)數(shù)據(jù)表的字段信息
1 select 2 a.name as FieldName, -- 字段名 3 a.isnullable, -- 是否可為空 4 b.Value as FieldDesc, -- 字段說(shuō)明 5 c.name as FieldType, -- 數(shù)據(jù)類(lèi)型 6 COLUMNPROPERTY(a.id,a.name,'IsIdentity') as isidentity, --是否標(biāo)識(shí)列 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('數(shù)據(jù)表名')新聞熱點(diǎn)
疑難解答
圖片精選