The following TSQL script will identify all tables in a databases that do not have a Primary Key:
EXEC sp_MSforeachtable ‘SELECT CASE WHEN OBJECTPROPERTY(OBJECT_ID(”?”), ”TableHasPrimaryKey”) = 0 THEN ”?” + ” – Missing PK” ELSE ”?” END’
The following TSQL script will identify all tables in a databases that do not have a Primary Key:
EXEC sp_MSforeachtable ‘SELECT CASE WHEN OBJECTPROPERTY(OBJECT_ID(”?”), ”TableHasPrimaryKey”) = 0 THEN ”?” + ” – Missing PK” ELSE ”?” END’