Query to find tables with no primary key constraints

  • Hi Guys,

    I'm looking for a query that will go through one of my databases, and give me a list of tables where there are no primary keys defined?

    I've had a look in the scripts section, but haven't been able to find anything that will help me.

    Any help would be appreciated!

    Cheers,

    Daniel

  • Hi Daniel,

    Try this:

    select * from information_schema.tables

    where objectproperty(object_id(table_name),'TableHasPrimaryKey') = 0

    Hope that helps,

  • Thanks Karl! That's working great!

    Cheers,

    Daniel

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply