I want to add a primary key to two tables, such that the values in the second table do not overlap those in the first table. The following doesn't work:
The last line gives an error message: Incorrect syntax near '@last' Expectiing +, - INTEGER or NUMERIC
Any suggestions welcome (I could of course do it by hand, but this is part of a future conversion, and I want to do everything in one fully automatic script)
Code:
DECLARE @last as int
ALTER TABLE dbo.Table1 ADD coKeyfield int PRIMARY KEY IDENTITY
SET @last = (SELECT TOP 1 coKeyfield FROM dbo.Table1 ORDER BY coKeyfield DESC)
ALTER TABLE dbo.Table2 ADD coKeyfield int PRIMARY KEY IDENTITY(@last+1,1)
Any suggestions welcome (I could of course do it by hand, but this is part of a future conversion, and I want to do everything in one fully automatic script)