SQL Server Performance

List tables that do not have primary keys

Discussion in 'Other SQL Server Blogs around the Web' started by Anonymous, Aug 2, 2007.

  1. Anonymous New Member

    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....(<a href="http://sqlserver-qa.net/blogs/t-sql/archive/2007/08/02/1227.aspx">read more</a>)<img src="http://sqlserver-qa.net/aggbug.aspx?PostID=1227" width="1" height="1">

Share This Page