Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trigger to insert new rows

Author  Topic 

loppis99
Starting Member

6 Posts

Posted - 2007-11-03 : 09:18:59
Hi,
I'm new at triggers and needs some help.

I have two tables, and on update in table_1, i want to insert the row in table_2


That works fine with one row, but if the update have two rows only one will be inserted in table_2

Help me please!!!!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-03 : 09:22:46
because your insert trigger did not handle set operations.

sample

insert into table_2( <col list> )
select <col list>
from inserted


Read these article on triggers http://www.sqlteam.com/tag/sql-server-triggers


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

loppis99
Starting Member

6 Posts

Posted - 2007-11-03 : 10:09:01
Thanks,
another question:
How can i set the column "Status" to 1 in table_2, in this trigger
That column does mot exist in table_1

Thanks again
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-03 : 10:11:33
[code]
insert into table_2( <col list>, status )
select <col list>, 1
from inserted
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

loppis99
Starting Member

6 Posts

Posted - 2007-11-03 : 10:20:23
Nice,
Thanks a lot
Go to Top of Page
   

- Advertisement -