Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 View

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2010-03-22 : 12:37:01
How could we determine programmatically what column is the unique ID for a view when no indexes exist for the view...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-22 : 13:19:57
It'll take a bit of work with multiple queries:

IF NOT EXISTS (
SELECT Column1, COUNT(*)
FROM YourView
GROUP BY Column1
HAVING COUNT(*) > 1)
PRINT 'Unique'

IF NOT EXISTS (
SELECT Column1, Column2, COUNT(*)
FROM YourView
GROUP BY Column1, Column2
HAVING COUNT(*) > 1)
PRINT 'Unique'

...

You'll need to do every combination of the columns, and even then you don't know if new data coming in will violate what you found. It's better to ask the people who know the data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -