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

Here is a quick script to list tables in database without primary key.

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

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


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


Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Database, SQL Constraint and Keys, SQL Scripts, SQL System Table
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

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.