April 30, 2005 at 4:58 am
i would like to know if it is possible to get data from one table and take it to another table..
for example
CREATE TABLE Company (dpt_no int unsigned not null auto_increment primary key, dpt_name char(20) not null, salary money not null)
****
CREATE TABLE sales_dpt (s.no int unsigned not null auto_increment primary key, first_name char(20) not null, last_name char(20) not null, dpt_name char(20) not null, , salary money not null)
****
i only want the salary column from Company table to go to salary column in the sales_dpt table automatically!!!
what would they trigger or stored procedure be?
thanx in advance
April 30, 2005 at 6:30 pm
Please be carefull not to duplicate posts. Leave replies here http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=9&messageid=178989
May 1, 2005 at 4:04 am
May 2, 2005 at 4:39 am
Do you want to update the salary column in the sales_dpt table to be updated whene you insert / update the company table. If this is your need, then you can write a trigger on insert/update on the company table, so whenever there is any new insert or update on the comapny table, it will reflect in the sales_dpt table.
However, if you want delete to be taken care of, then also write a delete trigger on the company table.
--Kishore
May 2, 2005 at 5:32 am
May 2, 2005 at 6:20 am
Do you want triggers for insert/update and delete ?
Let me know your specs. so that I can help you out.
--Kishore
May 2, 2005 at 6:38 am
The table scripts that you have given seems incorrect.
I have corrected the scripts. Also I have written 2 triggers.
CREATE TABLE Company
(dpt_no int not null identity(1,1) primary key,
dpt_name char(20) not null,
salary money not null)
****
CREATE TABLE sales_dpt
(sno int not null identity(1,1) primary key,
first_name char(20) not null,
last_name char(20) not null,
dpt_name char(20) not null,
salary money not null)
****
CREATE TRIGGER dbo.tr_company ON dbo.company for insert,update as
INSERT sales_dpt(dpt_name,salary)
SELECT dpt_name,salary
FROM inserted
****
CREATE TRIGGER dbo.tr_company_delete ON dbo.company for delete as
delete sales_dpt SELECT dpt_name,salary FROM deleted
Hope this helps.
--Kishore
May 2, 2005 at 8:15 am
May 3, 2005 at 4:35 am
No. You will have separate triggers for separate tables.
Read Triggers in BOL for more info.
--Kishore
Viewing 9 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply