July 19, 2005 03:19 PM

Using Fields as Primary Keys

Rating: (0)
SQL Server Magazine
InstantDoc ID #46890

What's a quick query to find out whether two fields together are unique and if I can use the combination as a primary key?

Intermediate and advanced users will know this is a simple query to write, however, I see questions like this regularly so I know it's a question that novices struggle with. Here's a simple query to get the information you want.

SELECT ColA,ColB,COUNT(*)
FROM TestTable
GROUP BY ColA,ColB
HAVING COUNT(*) > 1
In ...

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS