I have a table named Lead and another table named Sheet. I want to transfer the data in the table sheet to Table Lead. Also, I want the first ID of the table sheet to become the last ID of the lead table and the new IDs of the lead table will be filled as it is inserted. How to write the script in SQL Server.
How can I write a general script to do this for me?
1条答案
按热度按时间wtzytmuj1#
It sounds like you want to have an identity in your lead table, but prepopulate it with existing values.
Since you were kind enough not to provide any sample data or table definition, I'm going to wing it with some dummy tables:
One thing I don't like with this solution is that you're losing the connection between the original Sheet and Lead data. I'm not sure why you want to "first ID of the table sheet to become the last ID of the lead table", but if you don't, you can just change ROW_NUMBER thing to "id".