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 2000 Forums
 SQL Server Development (2000)
 Triggers?

Author  Topic 

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-07-19 : 13:28:55
I have 2 tables... simplicity sake.. a and b

create table a(
admin_seq int,
admin_autoNum int
)

create table b(
admin_seq int,
admin_autoNum int,
datacolumns
)

Now admin_autoNum is a number automatically assigned in table A using some algorithm. table B looks up this number inside table a (along with table c,d,e,f and all sorts of others tables)

Now table a is whats normally inserted on and then records can be inserted into other tables easily using the admin_seq and admin_autoNum columns as FK's. Everything works and we're all happy

However, a second program is being implemented that inserts directly into table B without making an entry in table a. My question is.. Is it possible to make a trigger on table b that upon insert...

1)creates an entry in table A (table A would then assign a value to admin_autoNum)
2)Looks up this newly entered admin_autoNum
3)Inserts the values into tableB along with the newly assigned admin_autonum


MSSQL 2000 if anyone cares

-----------------------
Take my advice, I dare ya

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-07-19 : 13:41:12
You might be able to get an INSTEAD OF trigger to do the job, in conjunction with IDENT_CURRENT().

Take a look at the BOL entries for both of these, cause I think there's a few examples that sound very close to what you're trying to do.

Go to Top of Page

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-07-19 : 14:27:51
Geez Rob.. I might as well just mail you a keg.


Thnx again

-----------------------
Take my advice, I dare ya
Go to Top of Page
   

- Advertisement -