WARDY IT Solutions - SQL Server Blog

Tables Without a Primary Key

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'

Published Wednesday, June 01, 2005 9:57 PM by admin
Anonymous comments are disabled