Is there a way to give a view a primary key in sql server. I know it is possible in oracle.
I am not concerned about updates its a read only view but someone else is using it in ms access so I would like the constraint that I know to be correct to be shown.
You cannot create a primary key on a view. In SQL Server you can create an index on a view but that is different to creating a primary key.
Expand Server- Database – tables – keys – right click key name and click modify, do the same process you did in SQL Server 2000, first you will uncheck allow null on that column, and then you will press control button and you will select all the columns you want to have in primary keys and then right click on those ...
To add to a response from @Ashraf, you can use select OBJECT_NAME(parent_object_id), * from sys. key_constraints where type = 'PK' . This will give you the table name and their primary key names for the tables that have a primary key.
Yes, you can create an indexed view, which must have a primary key. Note, this will persist the view data to disk, which may or may not be what you are looking for.
Also, creation of indexed views can also impact performance, both positively and negatively. Make sure you read up on the pros, cons, and limitations thoroughly before implementing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With