if exists (select * from sysobjects where name='tb_admin')
drop table tb_admin
go
create table tb_admin
(
id int identity(1,1) primary key,
aname varchar(50) not null
)
go
--存储过程
if exists (select * from sysobjects where name='proc_adminInsert')
drop procedure proc_adminInsert
go
create procedure proc_adminInsert
as
declare @name varchar(100);
declare @num int;
set @num=1;
set @name='admin_'
while(@num<=10)
begin
insert into tb_admin(aname) values(@name+convert(varchar(10),@num));
set @num+=1;
end
exec proc_adminInsert;
select * from tb_admin;
--创建修改触发器
if exists (select * from sysobjects where name='tge_Insert')
drop trigger tge_Insert
go
create trigger tge_Insert on tb_admin after update
as
update tb_admin set aname='tri_name' from inserted,tb_admin where tb_admin.id=inserted.id
go
update tb_admin set aname='' where id=1;
select * from tb_admin;
--创建删除触发器
if exists (select * from sysobjects where name='tge_Delete')
drop trigger tge_Delete
go
create trigger tge_Delete on tb_admin after delete
as
insert into tb_admin(aname) select aname from deleted;
go
delete tb_admin where id=11
select * from tb_admin;