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 |
ranjeetsingh_6
Posting Yak Master
125 Posts |
Posted - 2006-08-04 : 03:09:21
|
Hi I have some trigger on a table.Since Trigger create two special table inserted and deleted i want to see structure and contents of inserted and deleted table .How i will do.Ranjeet Kumar Singh |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-04 : 03:15:13
|
the inserted and deleted table only existed within the trigger. The structure is the same as the table of the trigger. KH |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-04 : 03:17:00
|
Here is a snippet from Books On Linequote: Using the inserted and deleted TablesTwo special tables are used in trigger statements: the deleted table and the inserted table. Microsoft® SQL Server™ 2000 automatically creates and manages these tables. You can use these temporary, memory-resident tables to test the effects of certain data modifications and to set conditions for trigger actions; however, you cannot alter the data in the tables directly.The inserted and deleted tables are used primarily in triggers to: Extend referential integrity between tables.Insert or update data in base tables underlying a view.Check for errors and take action based on the error.Find the difference between the state of a table before and after a data modification and take action(s) based on that difference. The deleted table stores copies of the affected rows during DELETE and UPDATE statements. During the execution of a DELETE or UPDATE statement, rows are deleted from the trigger table and transferred to the deleted table. The deleted table and the trigger table ordinarily have no rows in common.The inserted table stores copies of the affected rows during INSERT and UPDATE statements. During an insert or update transaction, new rows are added simultaneously to both the inserted table and the trigger table. The rows in the inserted table are copies of the new rows in the trigger table.An update transaction is similar to a delete operation followed by an insert operation; the old rows are copied to the deleted table first, and then the new rows are copied to the trigger table and to the inserted table.When you set trigger conditions, use the inserted and deleted tables appropriately for the action that fired the trigger. Although referencing the deleted table while testing an INSERT, or the inserted table while testing a DELETE does not cause any errors, these trigger test tables do not contain any rows in these cases.Note If trigger actions depend on the number of rows a data modification effects, use tests (such as an examination of @@ROWCOUNT) for multirow data modifications (an INSERT, DELETE, or UPDATE based on a SELECT statement), and take appropriate actions.
Refer to Books On Line for more information KH |
 |
|
ranjeetsingh_6
Posting Yak Master
125 Posts |
Posted - 2006-08-04 : 04:10:41
|
HiThanks for sending detail of inserted and deleted table.Ranjeet Kumar Singh |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-08-04 : 04:57:51
|
If you want to see the contents of the inserted or deleted tables you can do like this:CREATE TRIGGER myTriggerON dbo.myTableAFTER INSERT, UPDATE, DELETEAS SELECT * FROM insertedSELECT * FROM deleted The run an insert or delete-statement from query analyzer against dbo.myTable and see what happens...--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
|
|
|
|