BEGIN 中文man页面

系统
BEGIN 初始化一个事务块, 也就是说所有 BEGIN 命令后的用户语句都将在一个事务里面执行直到给出一个明确的 COMMIT [commit(7)] 或者 ROLLBACK [rollback(l)] 。缺省时,(没有 BEGIN),PostgreSQL 以 "autocommit" 模式执行事务,也就是说,每个语句在其自身的事务中执行, 并且在语句结束的时候隐含地执行一个提交(如果执行成功,否则执行回滚)。

NAME

BEGIN - 开始一个事务块

SYNOPSIS

BEGIN [ WORK | TRANSACTION ]

DESCRIPTION 描述

BEGIN 初始化一个事务块, 也就是说所有 BEGIN 命令后的用户语句都将在一个事务里面执行直到给出一个明确的 COMMIT [commit(7)] 或者 ROLLBACK [rollback(l)] 。缺省时,(没有 BEGIN),PostgreSQL 以 "autocommit" 模式执行事务,也就是说,每个语句在其自身的事务中执行, 并且在语句结束的时候隐含地执行一个提交(如果执行成功,否则执行回滚)。


 在事务块里执行的语句很明显地快得多, 因为事务开始/提交(start/commit)需要大量的CPU和磁盘活动。 在一个 事务内部执行多条语句对于修改若干个相关的表的时候也是很有用的: 在所有相关的更新完成之前,其它会话看不到中间的状态。  

PARAMETERS 参数

WORK
TRANSACTION

 可选关键字。没什么作用。

NOTES 注意

START TRANSACTION [start_transaction(7)] 有着和 BEGIN 一样的功能。


 使用 COMMIT [commit(7)] 或 ROLLBACK [rollback(7)] 结束一个事务。


 在一个现有事务块内部发出一个 BEGIN 将产生一个警告信息。 事务的状态将不会被影响。  

EXAMPLES 例子


 开始一个用户事务:

BEGIN;

COMPATIBILITY 兼容性

BEGIN 是 PostgreSQL 语言的扩展。 在 SQL 标准中没有明确的 BEGIN 的定义;事务初始化总是隐含的而且使用一个 COMMIT 或者 ROLLBACK 语句终止。


 许多关系型数据库为了方便提供一个自动提交(autocommit)特性。


 顺便说一句,BEGIN 关键字在嵌入 SQL 里用于不同的目的。 我们建议你在移植数据库应用时仔细检查事务的语义。  

SEE ALSO 参见

COMMIT [commit(7)], ROLLBACK [rollback(l)]

#p#

NAME

BEGIN - start a transaction block

SYNOPSIS

BEGIN [ WORK | TRANSACTION ]

DESCRIPTION

BEGIN initiates a transaction block, that is, all statements after BEGIN command will be executed in a single transaction until an explicit COMMIT [commit(7)] or ROLLBACK [rollback(l)] is given. By default (without BEGIN), PostgreSQL executes transactions in ``autocommit'' mode, that is, each statement is executed in its own transaction and a commit is implicitly performed at the end of the statement (if execution was successful, otherwise a rollback is done).

Statements are executed more quickly in a transaction block, because transaction start/commit requires significant CPU and disk activity. Execution of multiple statements inside a transaction is also useful to ensure consistency when making several related changes: other sessions will be unable to see the intermediate states wherein not all the related updates have been done.  

PARAMETERS

WORK
TRANSACTION
Optional key words. They have no effect.

NOTES

START TRANSACTION [start_transaction(7)] has the same functionality as BEGIN.

Use COMMIT [commit(7)] or ROLLBACK [rollback(7)] to terminate a transaction block.

Issuing BEGIN when already inside a transaction block will provoke a warning message. The state of the transaction is not affected.  

EXAMPLES

To begin a transaction block:

BEGIN;

COMPATIBILITY

BEGIN is a PostgreSQL language extension. There is no explicit BEGIN command in the SQL standard; transaction initiation is always implicit and it terminates either with a COMMIT or ROLLBACK statement.

Other relational database systems may offer an autocommit feature as a convenience.

Incidentally, the BEGIN key word is used for a different purpose in embedded SQL. You are advised to be careful about the transaction semantics when porting database applications.  

SEE ALSO

COMMIT [commit(7)], ROLLBACK [rollback(l)]

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-11-01 13:46:50

中文mantac

2011-08-25 16:55:26

gets中文man

2011-08-25 17:18:07

putc中文man

2011-08-25 15:49:02

freopen中文man

2011-08-25 16:00:56

fflush中文man

2011-08-25 16:08:55

fsetpos中文man

2011-08-25 15:33:18

exit中文man

2011-08-24 17:19:00

raw中文man

2011-08-25 10:55:37

services中文man

2011-08-25 09:35:26

units中文man

2011-08-24 16:16:07

LISTEN中文man

2011-08-24 13:57:35

DECLARE中文man

2011-08-11 15:28:43

ali中文man

2011-08-16 10:10:58

setup中文man

2011-08-23 17:18:44

umount中文man

2011-08-23 17:24:11

userdel中文man
点赞
收藏

51CTO技术栈公众号