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.
Author |
Topic |
HC@ZZF
Starting Member
5 Posts |
Posted - 2007-06-14 : 12:55:08
|
In oracle, I use the following script in trigger:INSERT INTO TABLE1 (CITY, STATE) VALUES (:new.city,:new.state);I am wondering how to insert new data in SQL server. Thanks! |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-06-14 : 13:00:52
|
there is an "inserted" table where the data is first inserted into before it goes into the actual table. So you can just SELECT from the inserted table.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
|
|
sshelper
Posting Yak Master
216 Posts |
Posted - 2007-06-14 : 13:01:20
|
In SQL Server, you read from the inserted system table for the newly inserted records in a table:INSERT INTO Table1 ( City, State )SELECT City, State FROM insertedSQL Server Helperhttp://www.sql-server-helper.com |
|
|
HC@ZZF
Starting Member
5 Posts |
Posted - 2007-06-14 : 13:21:07
|
I got it. Thanks! -Henry |
|
|
HC@ZZF
Starting Member
5 Posts |
Posted - 2007-06-14 : 14:05:21
|
What if I have delete and insert in trigger.Can you give me a example how to use IF to do it?Thanks!-Henryquote: Originally posted by sshelper In SQL Server, you read from the inserted system table for the newly inserted records in a table:INSERT INTO Table1 ( City, State )SELECT City, State FROM insertedSQL Server Helperhttp://www.sql-server-helper.com
|
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-06-14 : 14:49:12
|
No problem. There is a "Deleted" table too.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
|
|
|
|
|