Tuesday 2 October 2012

List Tables in a Database without a 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

No comments:

Post a Comment

Note: only a member of this blog may post a comment.