如何添加"X"行到SQL中的表? [英] How can I add "X" rows to a table in SQL?
本文介绍了如何添加"X"行到SQL中的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一张桌子,假设客户 我想从用户那里收到一个数字(表格),并在Customer表中创建X行. 假设客户在客户表中输入了4我想要4个新行. 我该怎么办?
If I have a table, let's say Customers and I want to receive from the user a number (Form) and create X rows in the Customer table. Let's say the customer put the number 4 I want 4 new rows at the Customer Table. How can I do this?
insert into Customer Valus ('Helen' , 36 )
推荐答案
您可以使用存储过程,然后传递要添加的客户数量.像这样...
You could use a stored procedure and then pass the number of customers you want added. Something like this...
create procedure AddNewCustomers
@NumberOfCustToAdd int
as
declare @counter int
set @counter = 0
while @counter < @NumberOfCustToAdd
begin
//put your insert statement here
set @counter = @counter + 1
end
go
然后,调用传递用户请求的客户数量的过程...
Then, call the procedure passing the number of customers that the user requested...
exec AddNewCustomers @NumberOfCustomersToCreate
这篇关于如何添加"X"行到SQL中的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文