@jimdrang 已经提供了答案,但是由于我刚刚使用 CREATE TABLE 和存储过程完成了一个完整的示例来完成这项工作,我想我不妨发布它,以帮助任何在路上寻找这个的人。
CREATE TABLE Cards
(
Cardnum int not null primary key,
price money not null,
booktype int not null,
service int not null
);
GO
CREATE PROCEDURE [dbo].[sp_AddCards] (
@Price money,
@BookType int,
@Service int,
@NumCards int,
@StartNum int
)
AS
BEGIN
DECLARE @CurCard int
SELECT @CurCard = @StartNum
WHILE @CurCard < @StartNum + @NumCards
BEGIN
INSERT INTO Cards (Cardnum, price, booktype, service)
VALUES (@CurCard, @Price, @BookType, @Service)
SELECT @CurCard = @CurCard + 1
END
END
GO
EXEC sp_AddCards @Price=9.99, @BookType=1, @Service=12, @NumCards=250, @Startnum=810041;
SELECT * FROM Cards;
DROP TABLE Cards;
DROP PROCEDURE sp_AddCards;
希望能帮助到你!