存储过程来填充数据,标记错误

时间:2019-05-31 05:43:00

标签: procedure

在SQL中有两个表可以用存储过程填充,其中只有一个可以使用,即创建5000000时的数据,另一个在执行时发送以下错误。消息245,级别16,状态1,过程sp_fingermass1,行339将varchar值'nomA1'转换为数据类型int时,转换失败。

create table tbldatos
 (
 id_datos int primary key,
 nomb varchar (200) not null, 
 email varchar (200) not null,

 create table Datos1
 (
   id_D1 int primary key,
   id_datos int,
   nomA varchar (200) not null, 
   emailA varchar (200) not null,
   foreign key (id_datos) references tbldatos (id_datos),
 )

--------程序-------

create procedure sp_llenarmasivo
as
declare @k int
set @k=1
while @k<=5000000
begin
insert into tbldatos values (@k,'nomb'+convert (varchar , @k), 'email'+ CONVERT(varchar , @k))
set @k=@k+1
end

execute sp_llenarmasivo;

select * from tbldatos

select id_datos,nomb,email from tbldatos

select tbldatos.id_datos,tbldatos.nomb,tbldatos.email from tbldatos


select *from tbldatos where nomb= 'nomb1'
select id_datos,nomb,email from tbldatos where nomb= 'nomb1'

-------------过程-------

create procedure sp_llenarmasivo1
as
declare @k int
set @k=1
while @k<=1000
begin
insert into Datos1 values(@k,'nomA'+CONVERT(varchar, @k),'emailA'+CONVERT(varchar, @k) , @k)
set @k=@k+1
end

exec sp_llenarmasivo1


select * from Datos1

0 个答案:

没有答案