向 SQL 视图添加主键
- 作者: 听说名字长的人长滴帅
- 来源: 51数据库
- 2023-02-07
问题描述
我在 SQL Server 数据库中创建了一个视图,它只是两个表的连接.
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?
谢谢
推荐答案
您必须创建物化(索引)视图才能添加唯一索引.但是你不能创建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
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
