为了减少数据库连接的I/O开销,一般会把多条数据插入放在一条SQL语句中一次执行.1.INSERT INTO TABLE(col1, col2) VALUES(val11, val12), (val21, val22),(val31,val32) ;2.INSERT INTO TABLE(col1, col2) SELECT val11, val12 UNION ALL SELECT val21, val22 union all select val31, val32 ; 这样的写法是属于复合S
) BEGIN 5 SET @S='' 8 BEGIN -@I) 10 BEGIN SET @S=@S+' ' END ELSE 14 BEGIN SET @S=@S+'**' 16 END END SET @S =@S+'*' 20 PRINT @S END 结果: ) BEGIN SET @S='' BEGIN -@I) BEGIN SET @S=@S+' ' END ELSE BEGIN SET @S=@S+'**' END END SET @S =@S+'*' PRINT @S END
declare @i int ,@j int ,@s nvarchar(max) set @i = 1 while @i <=9 begin set @s = ' ' set @j = 1 while @j <=@i begin set @s += cast(@j as char(1)) + '*' + cast(@i as char(1)) set @s += ' ' set @j +=1 end print @s set @i += 1 end declare @i int ,@j int