SDU Tools: Listing SQL Server user tables that have no primary key

SQL Server tables should have a primary key. I'm not talking about a clustering key (that's a different topic) but a key that logically identifies each row, and isn't ever NULL.

I have SQL purist friends that argue that a table without a primary key really isn't a table.

When I'm reviewing database designs, one of the things I look for is the lack of a primary key on tables. It's not just a purist issue. Without a primary key, other features like replication are problematic.

So, inĀ our free SDU Tools for developers and DBAs, we added a tool that can look for user tables that don't have a primary key. No surprise, it's called ListUserTablesWithNoPrimaryKey.

It takes three parameters:

@DatabaseName sysname – the database to look into
@SchemasToList nvarchar(max) – a comma-delimited list of schemas to check (or 'ALL')
@TablesToList nvarchar(max) – a comma-delimited list of table s to check (or 'ALL')

Find out more

You can see it in action in the main image above, and in the video here:

Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info:


Leave a Reply

Your email address will not be published. Required fields are marked *