unique identity or identifier for view in 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?
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.
精彩评论