sqlÖÐÓÃÓÚÊÂÎñ»Ø¹öµÄÓï¾ä
ʹÓà rollback Óï¾ä¿ÉÒÔ×÷·ÏδÌá½»ÊÂÎñÖеĸü¸Ä£¬½«Êý¾Ý¿â»Ö¸´µ½ÊÂÎñ×îÏÈʱµÄ״̬¡£
SQL ÖÐÓÃÓÚÊÂÎñ»Ø¹öµÄÓï¾ä
ÔÚ SQL ÖУ¬ÊÂÎñ»Ø¹öÓï¾äÓÃÓÚ×÷·ÏδÌá½»µÄÊÂÎñÖеÄËùÓиü¸Ä¡£Ëü½«Êý¾Ý¿â»Ö¸´µ½ÊÂÎñ×îÏÈʱµÄ״̬¡£
»Ø¹öÓï¾ä
ROLLBACK;
µÇ¼ºó¸´ÖÆ
Ó÷¨
»Ø¹öÓï¾ä¿ÉÒÔÔÚÊÂÎñÖеÄÈκÎʱ¿ÌÖ´ÐУ¬ÒÔ×÷·ÏÆù½ñΪֹËù×öµÄËùÓиü¸Ä¡£Ö´Ðлعöºó£¬ÊÂÎñÖеÄËùÓиü¸Ä½«±»ÑïÆú£¬²¢ÇÒÊý¾Ý¿â½«»Ö¸´µ½ÊÂÎñ×îÏÈʱµÄ״̬¡£
ʲôʱ¼äʹÓÃ
»Ø¹öÓï¾äͨ³£ÔÚÒÔÏÂÇéÐÎÏÂʹÓãº
Óöµ½¹ýʧ»òÒì³££¬ÎÞ·¨Íê³ÉÊÂÎñ¡£
Óû§¾öÒé²»Ìá½»ÊÂÎñ¡£
ÐèÒª×÷·ÏËù×öµÄ¸ü¸Ä²¢»Ö¸´µ½ÊÂÎñ×îÏÈʱµÄ״̬¡£
ʾÀý
BEGIN TRANSACTION; -- Ö´ÐÐһЩ SQL Óï¾ä¡£ ROLLBACK; -- ÊÂÎñÖеÄËùÓиü¸Ä¶¼±»×÷·Ï¡£
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
»Ø¹öÓï¾äÖ»ÊÊÓÃÓÚÄ¿½ñÔ˶¯ÊÂÎñ¡£ÈôÊÇÔÚÊÂÎñÌá½»ºóÖ´ÐлعöÓï¾ä£¬ÔòËü²»»á±¬·¢ÈκÎÓ°Ïì¡£
»Ø¹öÓï¾äÊDz»¿ÉÄæµÄ¡£Ò»µ©Ö´ÐУ¬Ëü½«ÓÀÊÀ×÷·ÏÊÂÎñÖеĸü¸Ä¡£
ÔÚʹÓûعöÓï¾ä֮ǰ£¬½¨Ò鱸·ÝÊý¾Ý£¬ÒÔ·À·ºÆðÈκÎÒâÍâÇéÐΡ£
ÒÔÉϾÍÊÇsqlÖÐÓÃÓÚÊÂÎñ»Ø¹öµÄÓï¾äµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡