List tables that do not have primary keys

Published 02 August 07 04:35 AM | SQL Master 

SELECT SCHEMA_NAME(schema_id) AS schema_name
    ,name AS table_name
FROM sys.tables
WHERE OBJECTPROPERTY(object_id,'TableHasPrimaryKey') = 0
ORDER BY schema_name, table_name;
GO

About the above function OBJECTPROPERY, BOL refers:  This function cannot be used for objects that are not schema-scoped, such as data definition language (DDL) triggers and event notifications.

Filed under: , ,

Comments

# SSQA.net - SqlServer-QA.net said on August 3, 2007 3:32 AM:

SELECT SCHEMA_NAME(schema_id) AS schema_name ,name AS table_name FROM sys.tables WHERE OBJECTPROPERTY

# Other SQL Server Blogs around the Web said on August 6, 2007 9:53 PM:

SELECT SCHEMA_NAME(schema_id) AS schema_name ,name AS table_name FROM sys.tables WHERE OBJECTPROPERTY

Anonymous comments are disabled

About SQL Master

**__________________________________** SQL Server MVP, Sr. DBA & industry expert. - Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.

Search

Go

This Blog

«August 2007»
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

Syndication