Get table names that dont have a primary key set

title says it all...


I want to get a list of all the tables within a specific database that do not have a primary key set.


many thanks in adv.

Phil
LVL 2
detox1978Asked:
Who is Participating?
 
obahatConnect With a Mentor Commented:
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND OBJECTPROPERTY(object_id(TABLE_NAME), 'TableHasPrimaryKey ') = 0
0
 
detox1978Author Commented:
thanks again obahat,

2nd question in 10mins you've answered correctly.


0
 
obahatCommented:
LOL. I didn't know this was a test... :)
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.