SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 trigger
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ragulhalan
Starting Member

India
1 Posts

Posted - 10/23/2012 :  06:31:52  Show Profile  Reply with Quote
I need to create a table t1 with empno,ename,salary,deptno
and a table t2 with empno,salary,bonus
now i need to create a trigger which inserts a row into t2 whenever a row is inserted in t1 with the bonus calculated of 10%.could somebody please help me ....urgent...

raul

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/23/2012 :  07:28:34  Show Profile  Reply with Quote
Would be something like below. The code compiles, but I have not tested.

If someone updated the salary in T1, did you want the salary and bonus to be updated in T2 as well? This does not do that.

Also, since you have salary in T1, you probably don't need salary column in T2 (unless you want to call it OriginalSalary and keep it as a record of what the original salary was)
CREATE TABLE dbo.T1(empNo INT, ename VARCHAR(255),salary DECIMAL(19,2), deptno VARCHAR(32))
GO

CREATE TABLE dbo.T2(empNo INT, salary DECIMAL(19,2), bonus DECIMAL(19,2))
GO

CREATE TRIGGER dbo.CopyIntoT2 ON dbo.T1
FOR INSERT 
AS
INSERT INTO dbo.T2
SELECT empNo, salary, 0.1*salary
FROM INSERTED;
GO
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000