DECLARE @C CHARACTER(20) /*声明列*/ DECLARE @NUM INT /*声明创建指定行数*/ DECLARE @sql CHARACTER(500) /*声明执行sql语句*/ SET @NUM = 10 /*定义为10列*/ WHILE ( @NUM > 0 ) BEGIN SET @C = CONVERT(CHARACTER(10), @NUM) /*设置列*/ SET @sql = ‘ALTER TABLE dbo.Table_1 ADD colu‘ + @C + ‘ CHARACTER(50)‘/*设置sql语句*/ EXEC(@sql) /*执行sql语句*/ SET @NUM = @NUM - 1 /*递减*/ END
效果图:
前提:先创建一张表
时间: 2024-10-03 15:24:49