Tag: Tables without Primary key

How to identify tables without Primary Key in SQL Server

To identify tables without primary key in SQL Server.


SELECT OBJECT_SCHEMA_NAME( OBJECT_ID ) AS SCHEMANAME, NAME AS TABLENAME
FROM SYS.TABLES
WHERE OBJECTPROPERTY(OBJECT_ID,'TABLEHASPRIMARYKEY') = 0 
ORDER BY SCHEMANAME, TABLENAME ;

Advertisements