在一段SQL后面加上GO,就意味着这段代码为一个batch,一起提交到实例,同时也是个事务,有异常就会回滚。
加go的效果和选中那段代码执行是一样的。
--创建示例表 create table #tmp (SN VARCHAR(100)) --插入10行数据,go后面的数字表示执行次数。 INSERT INTO #tmp VALUES('SADFASDF') GO 10 --go之前的所有SQL就是一个batch也是一个事物,他们一起提交实例 DELETE FROM #tmp INSERT INTO #tmp VALUES('','') GO --第二个SQL异常则都回滚,结果还是10行 SELECT * FROM #tmp