一些有用的查询语句(关于系统表的使用)
2006-05-22 23:11:07 来源:WEB开发网核心提示:--查找系统中所有的表(含表的行数) SELECT USER_NAME(uid), O.name, rowcnt(doampg), S.name, creation = O.crdate, case sysstat2 & 57344 when 32768 then 'datarows'
--查找系统中所有的表(含表的行数)
SELECT USER_NAME(uid),
O.name,
rowcnt(doampg),
S.name,
creation = O.crdate,
case sysstat2 & 57344
when 32768 then 'datarows'
when 16384 then 'datapages'
else 'allpages' end
FROM sysobjects O, sysindexes I, syssegments S
WHERE O.type = 'U' AND
O.id=I.id AND
I.indid IN (0,1) AND
I.segment=S.segment AND
O.type!='S'
ORDER BY 1,2
--查找系统中所有的主键
SELECT USER_NAME(O.uid), OBJECT_NAME(I.id),I.name,S.name
FROM sysindexes I,sysobjects O,syssegments S
WHERE I.id=O.id AND I.status2 & 2 = 2 AND
I.status & 2048 = 2048 AND
I.indid>0 AND I.segment=S.segment
ORDER BY USER_NAME(O.uid),OBJECT_NAME(I.id),I.name
--查找系统中所有的索引
SELECT USER_NAME(O.uid),O.name,I.name,
CASE WHEN ((I.status&16)=16 OR (I.status2&512)=512) THEN 'Clustered'
WHEN (I.indid=255) THEN 'Text/Image'
ELSE 'Non-Clustered' END,
CASE WHEN ((I.status&2)=2) THEN 'Unique'
ELSE 'Non-Unique' END, S.name
FROM sysindexes I,syssegments S,sysobjects O
WHERE I.indid>0 AND I.indid<255 AND I.status2 & 2!=2 AND
I.segment=S.segment AND O.id=I.id AND
O.type='U' AND O.type!='S' ORDER BY 1,2,3
--查找系统中所有表的外键
SELECT USER_NAME(O.uid),OBJECT_NAME(C.tableid),OBJECT_NAME(C.constrid)
FROM sysconstraints C,sysobjects O
WHERE C.constrid=O.id AND C.status=64
ORDER BY USER_NAME(O.uid),OBJECT_NAME(C.tableid),OBJECT_NAME(C.constrid)
更多精彩
赞助商链接