SQL Server 循环插入数据, while 循环使用

SQL Server 循环插入数据
IF EXISTS(SELECT * FROM sysobjects WHERE [name]='News')
    DROP TABLE [News]
GO
CREATE TABLE [News](
	[Id] [int] IDENTITY (1,1) PRIMARY KEY([Id]),
	[Title] [nvarchar](255),
);
GO

--循环插入数据
DECLARE @i [int];
SET @i=1;
WHILE @i<=10
BEGIN
	DECLARE @id uniqueidentifier;
	SET @id=NEWID();
	INSERT INTO [News]([Title])VALUES('标题 - '+CONVERT([nvarchar](50),@id));
	SET @i=@i+1;
END

SELECT * FROM [News];


热门推荐