随机生成数据,并对数据进行处理

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值