--查找系統中所有的表(含表的行數)
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)