开发者

unique identity or identifier for view in sql server 2005

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

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?


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


I wound up using a uniqueIdentifier field defaulted to NewID() and then populated the archive and current tables with GUIDs.

0

精彩评论

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