beginÔÚsqlÖÐÊÇʲôÒâ˼
ÔÚ sql ÖУ¬begin ÓÃÓÚ×îÏÈÒ»¸öÊÂÎñ£¬¸ÃÊÂÎñ½« sql Óï¾ä·Ö×éµ½Ò»¸öÂß¼µ¥Î»ÖУ¬ÒÔ±ã¶ÔÊý¾Ý¿âµÄ¸ü¸ÄÔÚÌύ֮ǰ¼á³ÖÔÝʱ״̬£¬²¢ÔÊÐíÔÚ±¬·¢¹ýʧʱ»Ø¹ö¸ü¸Ä¡£ÊÂÎñͨ³£ÓÃÓÚÈ·±£Êý¾ÝÍêÕûÐÔ¡¢Ô×ÓÐԺ͸ôÀëÐÔ¡£
BEGIN ÔÚ SQL ÖеļÄÒå
BEGIN ÔÚ SQL ÖÐÊÇÒ»¸öÊÂÎñ¿ØÖÆÓï¾ä£¬ÓÃÓÚ×îÏÈÒ»¸öÊÂÎñ¡£ËüָʾÊý¾Ý¿âÖÎÀíϵͳ (DBMS) ×îÏÈ´æ´¢ÓйØÕýÔÚÖ´ÐÐµÄ SQL Óï¾äµÄÐÅÏ¢£¬ÕâЩÐÅÏ¢³ÆΪÊÂÎñÈÕÖ¾¡£
×÷ÓÃ
BEGIN Óï¾ä½« SQL Óï¾ä·Ö×éµ½Ò»¸öÂß¼µ¥Î»£¨ÊÂÎñ£©ÖС£ÔÚÊÂÎñʱ´ú£º
¶ÔÊý¾Ý¿âËù×öµÄËùÓиü¸Ä¶¼ÊÇÔÝʱµÄ£¬Ö±µ½ÊÂÎñÌá½»»ò»Ø¹ö¡£
ÈôÊÇÊÂÎñʱ´ú±¬·¢¹ýʧ£¬Ôò¿ÉÒԻعöËùÓиü¸Ä£¬Ê¹Êý¾Ý¿â»Ö¸´µ½ÊÂÎñ×îÏÈÇ°µÄ״̬¡£
ÈôÊÇÊÂÎñÀÖ³ÉÍê³É£¬Ôò½«ÆäÌá½»£¬ÓÀÊÀµØÓ¦ÓöÔÊý¾Ý¿âµÄ¸ü¸Ä¡£
Óï·¨
BEGIN TRANSACTION;
µÇ¼ºó¸´ÖÆ
Ó÷¨
BEGIN Óï¾äͨ³£Óë COMMIT »ò ROLLBACK Óï¾äÒ»ÆðʹÓã¬ÒÔ¿¢ÊÂÊÂÎñ¡£ÀýÈ磺
BEGIN TRANSACTION; UPDATE customers SET balance = balance + 100 WHERE name = 'John Doe'; COMMIT TRANSACTION;
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬BEGIN Óï¾ä×îÏÈÒ»¸öÊÂÎñ£¬¸üвÙ×÷ÔÚÒ»¸öÊÂÎñÖÐÖ´ÐУ¬È»ºó COMMIT Óï¾ä½«¸ü¸ÄÓÀÊÀµØÓ¦Óõ½Êý¾Ý¿â¡£
ʲôʱ¼äʹÓà BEGIN£¿
Ó¦ÔÚÒÔÏÂÇéÐÎÏÂʹÓà BEGIN Óï¾ä£º
µ±ÐèҪȷ±£Êý¾ÝÍêÕûÐÔºÍÒ»ÖÂÐÔʱ¡£
µ±ÐèÒªÔ×ÓÐÔ£¬¼´ËùÓвÙ×÷ҪôËùÓÐÀֳɣ¬ÒªÃ´ËùÓÐʧ°Ü¡£
µ±ÐèÒª¸ôÀ룬¼´ÊÂÎñÖ´Ðв»ÊÜÆäËû²¢·¢ÊÂÎñµÄÓ°Ïìʱ¡£
ÒÔÉϾÍÊÇbeginÔÚsqlÖÐÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡