SQL query to determine that values in a column are unique

Solution 1:

Try this:

SELECT CASE WHEN count(distinct col1)= count(col1)
THEN 'column values are unique' ELSE 'column values are NOT unique' END
FROM tbl_name;

Note: This only works if 'col1' does not have the data type 'ntext' or 'text'. If you have one of these data types, use 'distinct CAST(col1 AS nvarchar(4000))' (or similar) instead of 'distinct col1'.

Solution 2:

select count(distinct column_name), count(column_name)
from table_name;

If the # of unique values is equal to the total # of values, then all values are unique.