June 11, 2008 at 9:34 am
Hi
I have a view that joins few tables and returns required result set.
The problem is there is no PrKey to this new view. I tried NEWID() ..will not work for me as this value changes everytime we run the view.
I would like to add a new column in my view that is generated automatically and can serve as Primary key here...similar to Identity col in a Table.
Is there a way.
Thanks.
June 11, 2008 at 9:42 am
considering you're in SQL 2005 - you could look into ROW_NUMBER() to do that for you. That being said - it generates things based on a specific order, so any DML statements are likely to change which number is assigned to a specific row.
You best bet might be to use some kind of compound number based on the PK's from the individual tables involved. Or - just simply use the multiple columns as your compound PK for the view (if you're going to go that far, consider making the view indexed, indexing based on this column combination).
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply