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 'ÓдíÎ󣬻عö'
ROLLBACK TRANSACTION--ÊÂÎñ»Ø¹öÓï¾ä
END
ELSE
BEGIN
PRINT '³É¹¦£¬Ìá½»'
COMMIT TRANSACTION--ÊÂÎñÌá½»Óï¾ä
END
1.ʲôÊÇÊÂÎñ£ºÊÂÎñÊÇÒ»¸ö²»¿É·Ö¸îµÄ¹¤×÷Âß¼µ¥Ôª£¬ÔÚÊý¾Ý¿âϵͳÉÏÖ´Ðв¢·¢²Ù×÷ʱÊÂÎñÊÇ×öΪ×îСµÄ¿ØÖƵ¥ÔªÀ´Ê¹Óõġ£Ëû°üº¬µÄËùÓÐÊý¾Ý¿â²Ù×÷ÃüÁî×÷Ϊһ¸öÕûÌåÒ»ÆðÏòϵÌá½»»ò³·Ïû£¬ÕâÒ»×éÊý¾Ý¿â²Ù×÷ÃüÁîҪô¶¼Ö´ÐУ¬ÒªÃ´¶¼²»Ö´ÐС£
2.ÊÂÎñµÄÓï¾ä
¡¡¿ªÊ¼ÊÂÎBEGIN TRANSACTION
¡¡Ìá½»ÊÂÎCOMMIT TRANSACTION
¡¡»Ø¹öÊÂÎñ£ºROLLBACK TRANSACTION
3.ÊÂÎñµÄ4¸öÊôÐÔ
¢ÙÔ×ÓÐÔ(Atomicity)£ºÊÂÎñÖеÄËùÓÐÔªËØ×÷Ϊһ¸öÕûÌåÌá½»»ò»Ø¹ö£¬ÊÂÎñµÄ¸öÔªËØÊDz»¿É·ÖµÄ£¬ÊÂÎñÊÇÒ»¸öÍêÕû²Ù×÷¡£
¢ÚÒ»ÖÂÐÔ(Consistemcy)£ºÊÂÎïÍê³Éʱ£¬Êý¾Ý±ØÐëÊÇÒ»Öµģ¬Ò²¾ÍÊÇ˵£¬ºÍÊÂÎ↑ʼ֮ǰ£¬Êý¾Ý´æ´¢ÖеÄÊý¾Ý´¦ÓÚÒ»ÖÂ״̬¡£±£Ö¤Êý¾ÝµÄÎÞËð¡£
¢Û¸ôÀëÐÔ(Isolation)£º¶ÔÊý¾Ý½øÐÐÐ޸ĵĶà¸öÊÂÎñÊDZ˴˸ôÀëµÄ¡£Õâ±íÃ÷ÊÂÎñ±ØÐëÊǶÀÁ¢µÄ£¬²»Ó¦¸ÃÒÔÈκη½Ê½ÒÔÀ´ÓÚ»òÓ°ÏìÆäËûÊÂÎñ¡£
¢Ü³Ö¾ÃÐÔ(Durability)£ºÊÂÎñÍê³ÉÖ®ºó£¬Ëü¶ÔÓÚϵͳµÄÓ°ÏìÊÇÓÀ¾ÃµÄ£¬¸ÃÐ޸ļ´Ê¹³öÏÖϵͳ¹ÊÕÏÒ²½«Ò»Ö±±£Áô£¬ÕæʵµÄÐÞ¸ÄÁËÊý¾Ý¿â
4.ÊÂÎñµÄ±£´æµã
SAVE TRANSACTION ±£´æµãÃû³Æ --×Ô¶¨Òå±£´æµãµÄÃû³ÆºÍλÖÃ
ROLLBACK TRANSACTION ±£´æµãÃû³Æ --»Ø¹öµ½×Ô¶¨ÒåµÄ±£´æµã
¶þÊÂÀý
ËùνÊÂÎñÊÇÖ¸Ò»×éÂß¼²Ù×÷µ¥Ôª£¬ËüʹÊý¾Ý´ÓÒ»ÖÖ״̬±ä»»µ½ÁíÒ»ÖÖ״̬¡£
°üÀ¨ËĸöÌØÐÔ:
1¡¢Ô×ÓÐÔ ¾ÍÊÇ
Ïà¹ØÎĵµ£º
ÔÚ¿ª·¢²»ÂÛÊÇWEB»¹ÊÇWinform³ÌÐòÖУ¬Êý¾Ý·ÖÒ³ÊǾ³£Óöµ½µÄÎÊÌ⣬ҪÊÇÔÚ´úÂëÖÐʵÏִ˹ý³Ì£¬ÏÔÈ»½µµÍÁË·þÎñÆ÷µÄЧÂÊ£¬¿ÉÒÔʹÓÃÒÔÏ´洢¹ý³ÌÀ´ÊµÏÖ¡£
CREATE PROCEDURE pagination
@tblName varchar(255), -- ±íÃû
@strGetFields varchar(1000) = '*', -- ÐèÒª·µ»ØµÄÁÐ
@fldName varchar(255)= ......
»Ö¸´Ä£Ê½£¨Recovery Model£©Ö¼ÔÚ¿ØÖÆÊÂÎñÈÕ־ά»¤¡£»Ö¸´Ä£Ê½ËµÃ÷Á˹¤×÷¶ªÊ§µÄ·çÏÕ£¬ÄÜ·ñ»Ö¸´µ½Ê±µã£¿
SQL ServerÊý¾Ý¿âÓÐÈýÖÖ»Ö¸´Ä£Ê½£º¼òµ¥»Ö¸´Ä£Ê½¡¢ÍêÕû»Ö¸´Ä£Ê½ºÍ´óÈÝÁ¿ÈÕÖ¾»Ö¸´Ä£Ê½¡£
Ïà¶ÔÓÚ¼òµ¥»Ö¸´Ä£Ê½¶øÑÔ£¬ÍêÕû»Ö¸´Ä£Ê½ºÍ´óÈÝÁ¿ÈÕÖ¾»Ö¸´Ä£Ê½ÌṩÁ˸üÇ¿µÄÊý¾Ý±£»¤¹¦ÄÜ¡£ÕâЩ»Ö¸´Ä£Ê½¶¼ÊÇ»ùÓÚ±¸·ÝÊÂÎñÈÕÖ ......
Óŵã:×ֶνÏÉÙ£¬ÓÐÔöɾ¸Ä²é¹¦ÄÜ£¬²»¹ý²éѯ̫Áýͳ¡£
ȱµã:
1.²»ËãÊÇÔÚºÜÕýµÄÎÞÏÞ·ÖÀà,ClassPathÕâ¸ö×ֶζ¨ÒåÏÞÖÆ¡£
2.Ö÷¼üCLASSID²»ÊÇ×ÔÔöµÄ£¬Ê¹ÓÃCODESMITHÅúÁ¿Éú³É¶à²ã¼Ü¹¹´úÂëÖлᵼÖ³ö´í¡£
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ArticleClass]') and OBJECTPROPERTY(id, N'IsUse ......
select * from pet;
insert into pet values('Liujingwei','Liuchao','cat','f','1984-04-18',null);
UPDATE pet set birth='1989-08-31' WHERE name='Slim';
select * from pet WHERE birth>'1998-1-1';
SELECT * from pet WHEREselect * from pet;
insert into pet values('Liujingwei','Liuchao','cat','f','198 ......
ÔÚ·Ö×éÅÅÐò¹ý³ÌÖÐÐèҪн¨ÅÅÐòÁУ¬°´Ìõ¼þ:(ÎïÁÏ·ÖÀà+¿Í»§Ãû³Æ) ½øÐзÖ×é»ã×Ü È»ºó¾Í¸ù¾Ý¸ÃÌõ¼þ½øÐÐÅÅÐò
1.ÐèҪƴ´ÕÁ½ÁÐ ×÷ΪÅÅÐòÁÐ,ÈçÐè¼ÓÈëÌØÊâ×Ö·û.¾Í»á±¨´í.
ÒòΪ±¾Éí¸Ä×ֶξÍÊÇvarcharÀàÐÍ ÐèÒª½«charÀàÐÍ'_' ת»»³Évarchar
2.Æ´´Õ¹ý³ÌÖÐÓпոñÐèҪȥ¿Õ¸ñ
e.g£ºselect (trim(ÎïÁÏ·ÖÀà)+to_char( ......