var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Get Primary Key from another Table
I've just tried realizing following project:
Currently i have separate Tables with separate Primary Keys (ascending separate Number regions).
Now I want to do the following:
Table - NewID
Field - ID - Identity
Field - IDproc - Sub-Data Number
Table - Data1 (IDProc=1)
Field - ID - Primary Key, generated NEW from NEWiD
Now great would be if I could add a new Recordset in Data1 and I could generate a New ID in 'NewID' trough a Trigger and Set it on the inserted Data, but that doesn't seem possible.
I was able to do it with the following trigger:
CREATE TRIGGER [getNewID] ON [dbo].[Data1]
DECLARE @newID int
INSERT INTO NewID (IDProc) VALUES(1)
SELECT @newID=(SELECT TOP 1 id FROM NewID WHERE IDProc=1 ORDER BY ID DESC)
UPDATE Data1 SET ID=@newID WHERE ID IS NULL
But as I can imagine this would get some problems if two users insert a Recordset at the same Time - right?
Is there somehow the possiblity to 'SET INSERTED.ID = @NewID' ??, because it's the only real ID I have in this table (beneath a TimeStamp wich I also couldn't use).
Thanks for any Help!!!