读书笔记:SQL SERVER 2008高级编程:批处理和脚本

来源:互联网 发布:新浪邮箱端口号 编辑:程序博客网 时间:2024/05/22 17:29

Chapter 9

批处理和脚本

脚本里可以包含多个批处理。它们之间用GO分开。

But one SQL batch only has one ‘Go’.

SQL Batch 是T-SQL 语句集合的逻辑单元。

Note: ‘ Go’ is not a T-SQLcommand.

GO’s definition:

1.      独立成行

2.      独立发送批处理到服务器

Every batch is independent, so  every batch error will not stop other  batch’s execution;


Their execution results are:   the first and third succeed, but the secondone failed.

3.      GO 不是一个T-SQL 语句

所以只有sql server认识Go.

When editor find the ‘Go’ word, it willconsider go as an end flag of one batch, then将其打包,幷将它作为一个单元发送给服务器(不包括GO), theServer self doesn’t know what the “GO” mean.

 

9.2.1. 批处理错误

批处理错误分为两种:

语法检测时错误(自己理解就是编译时错误)

运行时错误

注意:运行时错误和我们的C#的运行时错误有些不同,出现在运行中出现错误前的所有语句都已经被执行。只有用的是事务除外。

运行时错误会终止批处理继续执行。

 

9.2.2. When do we use SQL batch

1.  需要批处理的语句


2. 使用批处理简历优先级

在create DataBase Test后一行,要加个GO.

 

原创粉丝点击