你的存储过程没仔细看就发现:
你表aid定义的id列是int型的,你怎么插入‘ere’这样的值啊?
你在查查吧
你表aid定义的id列是int型的,你怎么插入‘ere’这样的值啊?
你在查查吧
解决方案 »
- 如何使一列数字(单价)精确到角。
- 急!!!SQL Server 2000数据库文件覆盖问题
- 同志们啊,快帮我看看这个触发器,怎么每次出发完植都是空的!!
- 要创建纯“时间”和纯“日期”的自定义数据类型该怎么做?
- 怎样配置某个用户权限,不能执行execute sp_helptext '存储过程名'
- ERP的問題
- 在线等,寻求解决方法 急!!!!!!!!!!
- 这个语句应该怎么写?
- 构造表关系出错,请教一下.应该是简单的问题!!!!!
- Sybase里头,还有哪一种字段类型支持大于255个字节的?
- 视图问题?
- select userno,[use] from detail 为何字段"use"要加"[ ]"?
create trigger tri_seq
on aid
for insert
on aid
for insert
as
begin
declare @a int
declare @str char(4)
declare @sql varchar(1000)
set @a=0
set @str=''
set @sql=''
while @a<10000
begin
select @str=right('000'+cast( @a as varchar(4)),4)
set @sql='insert into aid values('+@str+')'
exec(@sql)
set @a=@a +1
end
end
on aid
for insert
as
begin
declare @a int,@str char(4)
set @a=0
while @a<10000
begin
select @str=right('000'+cast( @a as varchar(4)),4)
exec('insert into aid values( '+@str+')')
set @a=@a +1
end
endINSTEAD OF 触发器不支持递归
create table aid (id char(4) not null)
go--创建触发器
create trigger tri_seq
on aid
instead of insert
as
begin
declare @a int,@str char(4)
set @a=0
while @a<10000
begin
select @str=right('000'+cast( @a as varchar(4)),4)
insert into aid values(@str) --这里直接这样写
set @a=@a +1
end
end
go--插入数据
insert into aid values('ere')
go--显示结果
select * from aid
go
create table aid (id char(4) not null)
go--插入10000万条记录
insert into aid
select id=right(10000+a.id+b.id+c.id+d.id,4)
from(
select id=0 union all select 1
union all select id=2 union all select 3
union all select id=4 union all select 4
union all select id=6 union all select 7
union all select id=8 union all select 9
) a,(
select id=0 union all select 10
union all select id=20 union all select 30
union all select id=40 union all select 40
union all select id=60 union all select 70
union all select id=80 union all select 90
) b,(
select id=0 union all select 100
union all select id=200 union all select 300
union all select id=400 union all select 400
union all select id=600 union all select 700
union all select id=800 union all select 900
) c,(
select id=0 union all select 1000
union all select id=2000 union all select 3000
union all select id=4000 union all select 4000
union all select id=6000 union all select 7000
union all select id=8000 union all select 9000
) d
order by id
goselect * from aid
godrop table aid
insert into aid values('33')
我想不能让33也插入进去,有没有好办法?
create trigger tri_seq
on aid
instead of insert
as
begin
declare @a int,@str char(4)
set @a=0
while @a<10000
begin
select @str=right('000'+cast( @a as varchar(4)),4)
insert into aid values( @str)
set @a=@a +1
end
end
insert into aid values('ere')