开发者

SQL Server View Primary Key

开发者 https://www.devze.com 2023-01-12 01:11 出处:网络
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

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 开发者_JS百科shown.


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.


Indexed view is the correct choice but a primary key as RedFilter said is not actually required. Though there are many requirements that you will be forced to have such as a clustered index.


Within MS Access you can create a Primary-key on the linked view using the SQL statement:

ALTER TABLE [TableName] ADD CONSTRAINT [PrimaryKeyName] PRIMARY KEY ([FieldName1, FieldName2, ...])

That said, using an Indexed View is the better solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号