METHOD 1 :
This is the shortest method to find all the tables that do not have a primary key. In this method, we need to use OBJECTPROPERTY to check each table property and filter it.
This is the shortest method to find all the tables that do not have a primary key. In this method, we need to use OBJECTPROPERTY to check each table property and filter it.
--This script is compatible with SQL Server 2005 and above.USE AdventureWorks2012GOSELECT SCHEMA_NAME(schema_id) AS [Schema name], name AS [Table name]FROM sys.tablesWHEREOBJECTPROPERTY(object_id,'TableHasPrimaryKey') = 0GO |
No comments:
Post a Comment