|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Insert TriggerI guess the first question is "Can you have two columns in two seperate
table share an Identity Column?" If there is a way, then I'll do that. The other solution that I have came up with is to have another table that generates the IDs and then insert it into the record on Insert. I need to know how to update a record contained in the Inserted table. I tried doing it directly but I keep getting the error that states you cannot alter the Inserted or Deleted tables. Any help would be appreciated. Hi Toppar,
I guess the first question is "Can you have two columns in two seperate table share an Identity Column?" -No you can´t. There is no sequence in SQL Server like in Oracle. YOu have to reference the table in your update statement using the primary keys to join the original on the inserted one: UPDATE SomeTable SET SomeColumn = SomeValue FROM SomeTable S Inner Join INSERTED I On S.JoinedColumns = s.JoinedColumns --AND other joined columns HTH, jens Suessmeyer. Hi Jens,
I did finally get my plan to finally work after a lot of pain. I pretty much had to do it your way but I had to add a default value so that the unique constraint of the primary key was satisfied. I'm still kind of new to row level locking in SQL Server, but if it works similar to that in Oracle, I think that what I did should work. If not, I have written code in the form to handle it and then retry if two users try to insert at the same time. Once again, thank you for the help. Jon... create table #t1(id int identity(1,2), j int)
insert into #t1(j) select 1 union all select 2 union all select 3 select * from #t1 go -------- the idenitites wont collide create table #t2(id int identity(0,2), j int) insert into #t2(j) select 1 union all select 2 union all select 3 -------- the idenitites wont collide select #t1.*, '#t1' from #t1 union all select #t2.*, '#t2' from #t2 id j ----------- ----------- ---- 1 1 #t1 3 2 #t1 5 3 #t1 0 1 #t2 2 2 #t2 4 3 #t2 (6 row(s) affected)
Other interesting topics
Does dynamic SQL allow table variables?
1 to many relationship between columns trouble using a temp table in another SELECT DBCC SHOWCONTIG question Problem with Cursor and Union in select SELECT info from table on a different server Executing Stored Procedure within Trigger Reducing 5 values to 1 value Moving indexes from a filegroup to another SELECT problem in stored procedure |
|||||||||||||||||||||||