Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQLÊÂÎñ´¦Àí


-sqlÊÂÎñ´¦Àí
----------------------Àí------------ÂÛ-----------------------
1.ʲôÊÇÊÂÎñ£ºÊÂÎñÊÇÒ»¸ö²»¿É·Ö¸îµÄ¹¤×÷Âß¼­µ¥Ôª£¬ÔÚÊý¾Ý¿âϵͳÉÏÖ´Ðв¢·¢²Ù×÷ʱÊÂÎñÊÇ×öΪ×îСµÄ¿ØÖƵ¥ÔªÀ´Ê¹Óõġ£Ëû°üº¬µÄËùÓÐÊý¾Ý¿â²Ù×÷ÃüÁî×÷Ϊһ¸öÕûÌåÒ»ÆðÏòϵÌá½»»ò³·Ïû£¬ÕâÒ»×éÊý¾Ý¿â²Ù×÷ÃüÁîҪô¶¼Ö´ÐУ¬ÒªÃ´¶¼²»Ö´ÐС£
2.ÊÂÎñµÄÓï¾ä
¿ªÊ¼ÊÂÎBEGIN TRANSACTION
Ìá½»ÊÂÎCOMMIT TRANSACTION
»Ø¹öÊÂÎñ£ºROLLBACK TRANSACTION
3.ÊÂÎñµÄ4¸öÊôÐÔ
     ¢ÙÔ­×ÓÐÔ(Atomicity)£ºÊÂÎñÖеÄËùÓÐÔªËØ×÷Ϊһ¸öÕûÌåÌá½»»ò»Ø¹ö£¬ÊÂÎñµÄ¸öÔªËØÊDz»¿É·ÖµÄ£¬ÊÂÎñÊÇÒ»¸öÍêÕû²Ù×÷¡£
  ¢ÚÒ»ÖÂÐÔ(Consistemcy)£ºÊÂÎïÍê³Éʱ£¬Êý¾Ý±ØÐëÊÇÒ»Öµģ¬Ò²¾ÍÊÇ˵£¬ºÍÊÂÎ↑ʼ֮ǰ£¬Êý¾Ý´æ´¢ÖеÄÊý¾Ý´¦ÓÚÒ»ÖÂ״̬¡£±£Ö¤Êý¾ÝµÄÎÞËð¡£
  ¢Û¸ôÀëÐÔ(Isolation)£º¶ÔÊý¾Ý½øÐÐÐ޸ĵĶà¸öÊÂÎñÊDZ˴˸ôÀëµÄ¡£Õâ±íÃ÷ÊÂÎñ±ØÐëÊǶÀÁ¢µÄ£¬²»Ó¦¸ÃÒÔÈκη½Ê½ÒÔÀ´ÓÚ»òÓ°ÏìÆäËûÊÂÎñ¡£
  ¢Ü³Ö¾ÃÐÔ(Durability)£ºÊÂÎñÍê³ÉÖ®ºó£¬Ëü¶ÔÓÚϵͳµÄÓ°ÏìÊÇÓÀ¾ÃµÄ£¬¸ÃÐ޸ļ´Ê¹³öÏÖϵͳ¹ÊÕÏÒ²½«Ò»Ö±±£Áô£¬ÕæʵµÄÐÞ¸ÄÁËÊý¾Ý¿â
4.ÊÂÎñµÄ±£´æµã
     SAVE TRANSACTION ±£´æµãÃû³Æ --×Ô¶¨Òå±£´æµãµÄÃû³ÆºÍλÖÃ
     ROLLBACK TRANSACTION ±£´æµãÃû³Æ --»Ø¹öµ½×Ô¶¨ÒåµÄ±£´æµã
-------------------ʵ------------------Àý----------------------------
BEGIN TRANSACTION--¿ªÊ¼ÊÂÎñ
DECLARE @errorSun INT --¶¨Òå´íÎó¼ÆÊýÆ÷
SET @errorSun=0 --û´íΪ0
UPDATE a SET id=232 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
UPDATE aa SET id=2 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
IF @errorSun<>0
BEGIN
PRINT 'ÓдíÎ󣬻عö'
ROLLBACK TRANSACTION--ÊÂÎñ»Ø¹öÓï¾ä
END
ELSE
BEGIN
PRINT '³É¹¦£¬Ìá½»'
COMMIT TRANSACTION--ÊÂÎñÌá½»Óï¾ä
END
sqlÊÂÎñ´¦Àí 
BEGIN TRANSACTION--¿ªÊ¼ÊÂÎñ
DECLARE @errorSun INT --¶¨Òå´íÎó¼ÆÊýÆ÷
SET @errorSun=0 --û´íΪ0
UPDATE a SET id=232 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
UPDATE aa SET id=2 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
IF @errorSun<>0
BEGIN
PRINT


Ïà¹ØÎĵµ£º

ÓÃADO¹ÜÀíSQL SERVER

ÓÃADO¹ÜÀíSQL SERVER
http://blog.csdn.net/cncco/archive/2009/11/09/4789123.aspx
ÔÚÈí¼þ¿ª·¢ÖУ¬³£³£ÐèҪΪ³ÌÐò½¨Á¢Sql ServerÊý¾Ý¿âµÄÔËÐл·¾³¡£Íê³ÉÈçÔÚSQL ServerÊý¾Ý¿âÖн¨Á¢É豸£¬½¨Á¢Êý¾Ý¿â£¬½¨Á¢±í¸ñ£¬·ÖÅäȨÏ޵ȹ¦ÄÜ£¬ÈçºÎ·½±ãµÄ½¨Á¢Ó¦ÓóÌÐòËùÐèSql Server»·¾³µÄÊý¾Ý¿â»·¾³£¬¶ø²»ÓÃÆô¶¯SQL Enterprise Manage ......

ÓÃADO¹ÜÀíSQL SERVER £¡

      ÔÚÈí¼þ¿ª·¢ÖУ¬³£³£ÐèҪΪ³ÌÐò½¨Á¢Sql ServerÊý¾Ý¿âµÄÔËÐл·¾³¡£Íê³ÉÈçÔÚSQL ServerÊý¾Ý¿âÖн¨Á¢É豸£¬½¨Á¢Êý¾Ý¿â£¬½¨Á¢±í¸ñ£¬·ÖÅäȨÏ޵ȹ¦ÄÜ£¬ÈçºÎ·½±ãµÄ½¨Á¢Ó¦ÓóÌÐòËùÐèSql Server»·¾³µÄÊý¾Ý¿â»·¾³£¬¶ø²»ÓÃÆô¶¯SQL Enterprise ManagerÄØ£¿
ÏÂÃæÀ´¿´£º 
¡¡¡¡Æô¶¯VB6.0£¬Ð½¨Ò»¸ö¹¤ ......

·ÀSQLÊý×Ö×¢È뺯Êý

·ÀSQLÊý×Ö×¢È뺯Êý
http://blog.csdn.net/cncco/archive/2007/10/03/1810540.aspx
·ÀSQL×¢È뺯Êý
³ÌÐò´úÂ룺
º¯Êý²¿·Ö========================================================================
'------------------------------------------------
'ÓÃ;:¼ì²éÊÇ·ñΪÊý×Ö,ÒÔ¼°Êý×ÖÊÇ·ñ³¬³ö·¶Î§
'ÊäÈë:¼ì²é×Ö·û,´ ......

ǶÈëʽSQLʵÑé


ʵÑéÄÚÈÝ£º
ÕÆÎÕSQL Server 2000µÄÔ¤±àÒë³ÌÐòNSQLPREP.EXEµÄʹÓã¨ÒԿα¾ÀýÌâ1½øÐе÷ÊÔ£©£»
ʵÑé²½Ö裺
Ò»¡¢Êý¾Ý¿â»·¾³ÅäÖÃ
1¡¢´´½¨xueshengÊý¾Ý¿â£¬½¨Á¢student±íµÈ£»
2¡¢¹Ø±Õsql server 2000·þÎñ¹ÜÀíÆ÷£»
3¡¢½«devtoolsÎļþ¼Ð¿½±´µ½£ºC:\Program Files\Microsoft SQL Server
4¡¢½«BinnÎļþ¼Ð¿½±´µ½£ºC:\Program ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ