sql server 2005 中视图的唯一标识或标识符
我有一个视图,它是两个具有重叠键的表的并集,我想唯一地标识行以供以后检索。如何向视图行添加标识或标识符列,以便稍后可以通过该值检索行?
I've got a view that's a union of two tables that have overlapping keys and I want to uniquely identify the rows for later retrieval. How can I add an identity or identifier column to the view rows so I can retrieve the rows later by that value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有您的表定义,很难回答。但是,您不能在视图上创建人工键吗,例如:
SELECT 'TABLE1' + CAST(KeyColumn AS VARCHAR) AS 'Key'
从
TABLE1
UNION
SELECT 'TABLE2' + CAST(KeyColumn AS VARCHAR) AS 'Key'
从
表2
Hard to answer without your table definitions to hand. However, could you not create an artificial key on the view e.g:
SELECT 'TABLE1' + CAST(KeyColumn AS VARCHAR) AS 'Key'
FROM
TABLE1
UNION
SELECT 'TABLE2' + CAST(KeyColumn AS VARCHAR) AS 'Key'
FROM
TABLE2
我最终使用了默认为 NewID() 的 uniqueIdentifier 字段,然后使用 GUID 填充存档和当前表。
I wound up using a uniqueIdentifier field defaulted to NewID() and then populated the archive and current tables with GUIDs.