if exists(select name from sysobjects
where name = 'emp_khbh1' and type = 'u')
drop table emp_khbh1
go
create table emp_khbh1(ickh int,empbh int,xm char(12))
go
--处理重复的记录
if exists (select name from sysobjects
where name = 'chanage' and type = 'tr')
drop trigger chanage
go
create trigger chanage
on emp_khbh1
instead of insert
as
begin
insert into emp_khbh1(ickh,empbh,xm)
select ickh=(case when exists(select 1 from emp_khbh1 a where a.ickh=ickh ) then ickh-1 else ickh end)
,empbh=empbh
,xm=xm
from inserted
end
go
--随机生成一个表的数据
if exists (select name from sysobjects
where name = 'sj_rand' and type = 'P')
drop proc sj_rand
go
create proc sj_rand @m int
as
begin
declare @n int
set @n=1
while @n< =@m
begin
insert into emp_khbh1(ickh,empbh,xm)
select ickh=cast(1000000+rand()*10000000 as int),empbh=10000+@n, xm=
nchar(19999+(case when rand()*10000<=2000 then rand()*10000 else rand()*1000 end))+
(case when (19968+rand()*30000)<19968+20902 then nchar(19968+rand()*10000) else ' ' end)+
nchar(19968+(case when rand()*10000<=20902 then rand()*10000 else rand()*1000 end))
set @n=@n+1
end
end
go
--调用proc
exec sj_rand 100
go
select * from emp_khbh1
go
where name = 'emp_khbh1' and type = 'u')
drop table emp_khbh1
go
create table emp_khbh1(ickh int,empbh int,xm char(12))
go
--处理重复的记录
if exists (select name from sysobjects
where name = 'chanage' and type = 'tr')
drop trigger chanage
go
create trigger chanage
on emp_khbh1
instead of insert
as
begin
insert into emp_khbh1(ickh,empbh,xm)
select ickh=(case when exists(select 1 from emp_khbh1 a where a.ickh=ickh ) then ickh-1 else ickh end)
,empbh=empbh
,xm=xm
from inserted
end
go
--随机生成一个表的数据
if exists (select name from sysobjects
where name = 'sj_rand' and type = 'P')
drop proc sj_rand
go
create proc sj_rand @m int
as
begin
declare @n int
set @n=1
while @n< =@m
begin
insert into emp_khbh1(ickh,empbh,xm)
select ickh=cast(1000000+rand()*10000000 as int),empbh=10000+@n, xm=
nchar(19999+(case when rand()*10000<=2000 then rand()*10000 else rand()*1000 end))+
(case when (19968+rand()*30000)<19968+20902 then nchar(19968+rand()*10000) else ' ' end)+
nchar(19968+(case when rand()*10000<=20902 then rand()*10000 else rand()*1000 end))
set @n=@n+1
end
end
go
--调用proc
exec sj_rand 100
go
select * from emp_khbh1
go