Sometime back I had done a post called Find all tables in a database without a primary key where I used the INFORMATION_SCHEMA.TABLES.
Megan commented asking how to rewrite the same query using sys.objects. Well here it is!
USE NerdDinner;
GO
SELECT name as [TableName], create_date
FROM sys.objects
WHERE type = 'U'
AND OBJECTPROPERTY([object_id], 'TableHasPrimaryKey') = 0;
GO
If you do not get any results, then all your tables in your database have primary keys
You may also want to check the following related posts written some time ago:
Find Primary Key of a SQL Server Table
List all the Non-Clustered Indexes in a SQL Server Database
Find out all the Primary Key and Foreign Key Constraints in a table
Hi, The above articles is very impressive, and I really enjoyed reading your blog and points that you expressed. I love to come back on a regular basis, pl. post more on the subject. Thanks.
ReplyDeleteThanks for providing such a nice post.
ReplyDeleteI liked your post and will definately link your blog in my website.
keep updating yourself.