create table trig_parent(id int ,name varchar(20))
create table trig_child(id int ,name varchar(20))
create trigger trg_parent_id on trig_parent
for insert
as
begin
declare @id int,@name varchar(20)
select @id=id,@name=name from inserted
insert into trig_child values(@id,@name)
end
select *from trig_parent
select * from trig_child
alter table trig_parent add sno int identity(1,1)
update trig_parent set name='vinoth'
insert into trig_parent values(4,'new')
create trigger trg_parent_upd on trig_parent
for update
as
begin
declare @id int,@name varchar(20)
select @id=id,@name=name from inserted
insert into trig_child values(@id,@name)
select @id=id,@name=name from deleted
insert into trig_child values(@id,@name)
end
select * from trig_parent where name='vinoths'
delete from trig_parent where sno in(select sno from (select ROW_NUMBER() over(partition by name order by name) sr_no,* from trig_parent)x
where sr_no<>1)
select sno from (select ROW_NUMBER() over(partition by name order by name) sr_no,* from trig_parent)x
where sr_no<>1
No comments:
Post a Comment