本文介紹了向 SQL 視圖添加主鍵的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在 SQL Server 數(shù)據(jù)庫中創(chuàng)建了一個視圖,它只是兩個表的連接.
I have created a view in a SQL Server database which is just a join of two tables.
有什么辦法可以在這個視圖的行中插入一個唯一的主鍵……或者我不確定如何將其中一個列名指定為主鍵……有什么想法嗎?
Is there any way I can insert a unique primary key into the rows of this view ...or I'm not sure how I can specify one of the column names to be a primary key...any ideas?
謝謝
推薦答案
您必須創(chuàng)建物化(索引)視圖才能添加唯一索引.但是你不能創(chuàng)建PK約束.
You would have to create materialized (indexed) view in order to be able to add unique index. But you can't create PK constraint.
CREATE VIEW v_test
WITH SCHEMABINDING --optional
AS
SELECT id from table
GO
CREATE UNIQUE CLUSTERED INDEX idx_id
ON v_test (id)
GO
這篇關(guān)于向 SQL 視圖添加主鍵的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!