Re: Easy Trigger "?" question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Hari (hari_prasad_k_at_hotmail.com)
Date: 05/26/04


Date: Wed, 26 May 2004 09:13:42 +0530

Hi,

You can use one of the below

1. Stored Procedures
2. Insert Trigger

You can write a stored procedure

1. First the protecure insert the data in to the tableA, Once the insert is
successful. The same SP can fire 4 inserts to load the other tables

2. Write a Insert Trigger to fire when there is an insert in tablea and load
the other tables.

Sample for insert trigger

-- creation of 3 tables

create table tablea( a int)
go
create table tableb( a int)
go
create table tablec( a int)
go
-- INsert trigger
create trigger ins on tablea for insert
as
insert into tableb select * from inserted
insert into tablec select * from inserted
go
-- insert statement
insert into tablea values(3)
go
select * from tablea
go
select * from tableb
go
select * from tablec

Thanks
Hari
MCDBA

"steve.beasley" <anonymous@discussions.microsoft.com> wrote in message
news:BE0DB5D7-8AE0-4F5D-A9F4-CC37AC2DBA2D@microsoft.com...
> I would like to know the best method (detailed if possible) for
duplicating primary keys. I have a database with 5 tables, (tableA,
tableB...) each with a primary key of JobNumber. If and when someone
inserts a new JobNumber into Table A, I would like the corresponding field
in the other four tables to be populated as well.



Relevant Pages

  • Can We Explain Missing Rows?
    ... My database has TableA and TableB. ... Table A contains a DELETE trigger that removes rows from TableB (TableA has ...
    (microsoft.public.sqlserver.programming)
  • Re: Can We Explain Missing Rows?
    ... >> Your trigger can only handle a delete statement affecting one row. ... I just discovered that TableA is missing a bunch of rows ... >>> CREATE Procedure DeleteAccessController ...
    (microsoft.public.sqlserver.programming)
  • Re: Calling an SQL function from within an Oracle trigger
    ... Before insert or update on a table tableA, I need to check if the value ... I want to have a trigger before insert or update on tableA which calls ... I use the return value to either allow the insert/update or disallow ... Your best source for information on how to code triggers is probably ...
    (comp.databases.oracle.misc)
  • How do I create a trigger in a stored procedure?
    ... I want a stored procedure to: ... Delete existing trigger on TableA ... WHERE (LanguageCode 'EN-US') ...
    (microsoft.public.sqlserver.programming)
  • Re: Trigger, alternative way to pass variable to trigger
    ... What we did was have our object that we used to call stored procedures add ... Then in the trigger or default constraints, I used a user defined function ... system function, though just calling it as master.. ... >>Pro SQL Server 2000 Database Design ...
    (microsoft.public.sqlserver.programming)