SQL 2005

Is there a way to find all tables in a database that do not have a Primary key?
dastaubAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
rtayConnect With a Mentor IT DirectorCommented:
This should work.


USE DatabaseName;
GO
SELECT SCHEMA_NAME(schema_id) AS SchemaName,name AS TableName
FROM sys.tables
WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
ORDER BY SchemaName, TableName;
GO
0
 
Paul-BConnect With a Mentor Commented:
like this

USE NameOfDatabase;
GO
SELECT SCHEMA_NAME(schema_id) AS SchemaName,name AS TableName
FROM sys.tables WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
ORDER BY SchemaName, TableName;
GO

Open in new window

0
 
dastaubAuthor Commented:
could you add to this query the row count of the tables?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.