How to find out whether a table has some unique columns

Viewed 20027

I use MS SQL Server.

Ive been handed some large tables with no constrains on them, no keys no nothing.

I know some of the columns have unique values. Is there a smart way for a given table to finde the cols that have unique values ?

Right now I do it manually for each column by counting if there is as many DISTINCT values as there are rows in the table.

SELECT COUNT(DISTINCT col) FROM table

Could prob make a cusor to loop over all the columns but want to hear if someone knows a smarter or build-in function.

Thanks.

5 Answers
Related