SQL循环插入测试数据

用到两个点,一个是while循环,一个是exec sp_executesql

DECLARE @i AS INT = 20;
DECLARE @s AS nvarchar(50) = '';
DECLARE @e AS nvarchar(MAX) = '';
WHILE
		@i < 100 BEGIN
			SET @s ='Group'+CAST(@i AS nvarchar (50));
			SET @e = N'INSERT INTO [dbo].[Test2020]([OId], [Id], [NormalizedName], [ConcurrencyStamp], [Name], [DisplayName], [Description], [IsStatic], [IsDefault], [ExpireTime], [IsDeleted], [DeleterUserId], [DeletionTime], [LastModificationTime], [LastModifierUserId], [CreationTime], [CreatorUserId]) VALUES (''FFEE07F0-32AC-4AC7-9A12-000689654898'',''' + CAST(NEWID() AS nvarchar(50)) + ''', N''' +@s + ''', NULL, N''' +@s + ''', N'''+@s+''', N''' +@s + ''', ''1'', ''0'', NULL, ''0'', NULL, NULL, NULL, NULL, ''2020-05-05 20:13:55.000'', ''1B7C5D17-E5F0-44A2-9B74-479EDFC4EDC2'');';
			exec sp_executesql @e;
		SET @i =@i + 1;
END

  

posted @ 2020-05-05 20:34  devs  阅读(324)  评论(0编辑  收藏  举报