天天看点

Mssql 查询没有主键的表的表名

WITH alltabs AS (SELECT cast(B.NAME as varchar()) AS TABNAME
        FROM sys.extended_properties A INNER JOIN sys.tables B ON A.MAJOR_ID = B.OBJECT_ID
        WHERE A.MINOR_ID = '0')
SELECT m.* FROM  alltabs m WHERE m.TABNAME NOT IN (select t3.TABNAME from sysobjects t1,sysobjects t2,alltabs t3 WHERE t2.name =t3.TABNAME and t1.parent_obj = t2.id
and t1.xtype='PK')