Get last Inserted value and Insert into another table using trigger


First Create a table name- employee and temp_employee
CREATE TABLE [dbo].[Employee]
(
[Id] [int] IDENTITY(1,1) NOT NULL Primary key,  
[name] [varchar](100) NULL,
[salary] [float]
)CREATE TABLE [dbo].[temp_Employee]
(
    [Id] [int] IDENTITY(1,1) NOT NULL Primary key,
    emp_id int NULL
)
Now create a trigger

CREATE TRIGGER trg_Insert
   ON  dbo.employee
          AFTER INSERT
AS
BEGIN
         
SET NOCOUNT ON;
          INSERT INTO dbo.temp_employee (emp_id)  select id from inserted
END
GO
Get last Inserted value and Insert into another table using trigger Get last Inserted value and Insert into another table using trigger Reviewed by kamal kumar das on February 24, 2012 Rating: 5

No comments:

ads 728x90 B
Powered by Blogger.