Howdy! Need help on writing a trigger. I need to write a
trigger so that when a record is updated/inserted in one
table, that the contents of that record are also inserted
in another table. Any ideas?
Howdy! Need help on writing a trigger. I need to write a
trigger so that when a record is updated/inserted in one
table, that the contents of that record are also inserted
in another table. Any ideas?
There are lot of details & examples in SQL Server Books Online.
Normally you can write something along the lines of:
CREATE TRIGGER trg ON tbl
FOR INSERT, UPDATE
AS
INSERT anothertbl (col1, col2, ..coln)
SELECT *
FROM inserted
INNER JOIN tbl
ON inserted.key = tbl.key
GO
--
- Anith
(Please respond only to newsgroups)
Inside the trigger write...
insert youraudittable (.... )
select ....
from inserted
The inserted and deleted tables contain the rows just
updated/inserted/deleted.
--
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com
Quote:> Howdy! Need help on writing a trigger. I need to write a
> trigger so that when a record is updated/inserted in one
> table, that the contents of that record are also inserted
> in another table. Any ideas?
>insert youraudittable (.... )
> select ....
> from inserted
>The inserted and deleted tables contain the rows just
>updated/inserted/deleted.
>--
>Tony Rogerson
>SQL Server MVP
>http://www.sqlserverfaq.com
message
>> Howdy! Need help on writing a trigger. I need to
write a
>> trigger so that when a record is updated/inserted in one
>> table, that the contents of that record are also
inserted
>> in another table. Any ideas?
>.
As Anith's example points out, you need to join the inserted table to the
main table somehow, e.g. if you have a key on the main table.
--
Aaron Bertrand, SQL Server MVP
http://www.aspfaq.com/
Please reply in the newsgroups, but if you absolutely
must reply via e-mail, please take out the TRASH.
> >-----Original Message-----
> >Inside the trigger write...
> >insert youraudittable (.... )
> > select ....
> > from inserted
> >The inserted and deleted tables contain the rows just
> >updated/inserted/deleted.
> >--
> >Tony Rogerson
> >SQL Server MVP
> >http://www.sqlserverfaq.com
> message
> >> Howdy! Need help on writing a trigger. I need to
> write a
> >> trigger so that when a record is updated/inserted in one
> >> table, that the contents of that record are also
> inserted
> >> in another table. Any ideas?
> >.
Ah, I understand now. It worked as it should when you do
the join. Thank you!
1. Help..join on two table , Selecting records from two tables
I am new to Oracle and I am trying to figure out a way to do a select on two tables.
Table A
--------
Col 1A, Col 2A
Table B
--------
Col 1B, Col 2B
Here is my query:
Select * from TableB where TableA.Col1A=TableB.Col1B and TableA.Col2A <> 1
This seems to return also some records where Col2A = 1
I will appreciate if someone can help.
Thanks in advance
2. multiple sql calls into a temporary table
3. Selecting unequal fields from two records in two tables based on PK being equal
5. Create One Record Set from two Tables located in Two Databases
7. Lost Record in Answer Table with running a query including two tables in Paradox 5.0
9. Adding record in one table from form with two tables
10. Records in Table 1 excluding those in table two
11. Writing rows from two tables to one text file
12. Retrieve data from two tables, from two databases, in two registered servers
13. recordset should show two fields from two tables, tables have nothing in common