SQLServer批量插数据

--批量插数据,以用户表为例
--表结构
create table [user]
(
UserID int not null primary key IDENTITY(1,1),
name varchar(20)not null,
PWD varchar(20)not null,
sex varchar(4)
)


--批量插入用户数据100条
declare @UserID varchar(20), @Record int ,@i int

set @Record=100
select @UserID=UserID  from [user]
set @i=@UserID+1
print @i

while (@i <= @Record)
begin
insert into [user](name,PWD,sex)
select
 '用户名'+right(replicate('0',10)+cast(@i as varchar(32)),10),
 '123456',
 '男'
set @i=@i+1
end

你可能感兴趣的:(SQL)