Is it possible to set a primary key to a view in SQLServer 2008?
Asked
Active
Viewed 3,443 times
5
-
No, I don't think so. – Zeal Jun 17 '10 at 14:55
1 Answers
6
You can create a clustered index on a SQL Server view - it's called an indexed view.
See Improving Performance with SQL Server 2008 Indexed Views for details.

marc_s
- 732,580
- 175
- 1,330
- 1,459
-
And unique constraints can be applied as well so that's 99% of the way there. – Martin Smith Jun 17 '10 at 15:07
-
Yes, once the clustered index is in place, other indices can be added - including unique indices – marc_s Jun 17 '10 at 15:16
-
1+1: SQL Server calls it an indexed view, but it's generally referred to as being a Materialized View. But there are constraints to materialized/indexed views: http://technet.microsoft.com/en-us/library/cc917715.aspx#XSLTsection126121120120 – OMG Ponies Jun 17 '10 at 15:39