SQL SERVER – 2005 – List Tables in Database Without Primary Key

This is very simple but effective script. It list all the table without primary keys.

USE DatabaseName;
GO
SELECT SCHEMA_NAME(schema_id) AS SchemaName,name AS TableName
FROM sys.tables
WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
ORDER BY SchemaName, TableName;
GO



Reference : Pinal Dave (https://blog.sqlauthority.com), BOL

, , ,
Previous Post
SQL SERVER – Fix: Error 2596 The repair statement was not processed. The database cannot be in read-only mode
Next Post
SQL SERVER – 2005 – SSMS – Enable Autogrowth Database Property

Related Posts

28 Comments. Leave new

Leave a Reply

Menu