MySQLʹÓô¥·¢³ÌÐò
´¥·¢³ÌÐòÊÇÓë±íÓйصÄÃüÃûÊý¾Ý¿â¶ÔÏ󣬵±±íÉϳöÏÖÌض¨Ê¼þʱ£¬½«¼¤»î¸Ã¶ÔÏó¡£ÔÚijЩ´¥·¢³ÌÐòµÄÓ÷¨ÖУ¬¿ÉÓÃÓÚ¼ì²é²åÈëµ½±íÖеÄÖµ£¬»ò¶Ô¸üÐÂÉæ¼°µÄÖµ½øÐмÆËã¡£
´¥·¢³ÌÐòÓë±íÏà¹Ø£¬µ±¶Ô±íÖ´ÐÐINSERT¡¢DELETE»òUPDATEÓï¾äʱ£¬½«¼¤»î´¥·¢³ÌÐò¡£¿ÉÒÔ½«´¥·¢³ÌÐòÉèÖÃΪÔÚÖ´ÐÐÓï¾ä֮ǰ»òÖ®ºó¼¤»î¡£ÀýÈ磬¿ÉÒÔÔÚ´Ó±íÖÐɾ³ýÿһÐÐ֮ǰ£¬»òÔÚ¸üÐÂÁËÿһÐк󼤻·¢³ÌÐò¡£
ÒªÏë´´½¨´¥·¢³ÌÐò»òÉáÆú´¥·¢³ÌÐò£¬¿ÉʹÓÃCREATE TRIGGER»òDROP TRIGGERÓï¾ä
ÏÂÃæ¸ø³öÁË1¸ö¼òµ¥µÄʾÀý£¬ÔÚ¸ÃʾÀýÖУ¬Õë¶ÔINSERTÓï¾ä£¬½«´¥·¢³ÌÐòºÍ±í¹ØÁªÁËÆðÀ´¡£Æä×÷ÓÃÏ൱ÓÚÀÛ¼ÓÆ÷£¬Äܹ»½«²åÈë±íÖÐijһÁеÄÖµ¼ÓÆðÀ´¡£
ÔÚÏÂÃæµÄÓï¾äÖУ¬´´½¨ÁË1¸ö±í£¬²¢Îª±í´´½¨ÁË1¸ö´¥·¢³ÌÐò£º
mysql> CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
mysql> CREATE TRIGGER ins_sum BEFORE INSERT ON account
-> FOR EACH ROW SET @sum = @sum + NEW.amount;
CREATE TRIGGERÓï¾ä´´½¨ÁËÓëÕË»§±íÏà¹ØµÄ¡¢ÃûΪins_sumµÄ´¥·¢³ÌÐò¡£Ëü»¹°üÀ¨Ò»Ð©×Ӿ䣬ÕâЩ×Ó¾äÖ¸¶¨ÁË´¥·¢³ÌÐò¼¤»îʱ¼ä¡¢´¥·¢³ÌÐòʼþ¡¢ÒÔ¼°¼¤»î´¥·¢³ÌÐòʱ×÷Щʲô£º
· ¹Ø¼ü×ÖBEFOREÖ¸Ã÷ÁË´¥·¢³ÌÐòµÄ¶¯×÷ʱ¼ä¡£ÔÚ±¾ÀýÖУ¬Ó¦ÔÚ½«Ã¿Ò»ÐвåÈë±í֮ǰ¼¤»î´¥·¢³ÌÐò¡£ÕâÀàÔÊÐíµÄÆäËû¹Ø¼ü×ÖÊÇAFTER¡£
· ¹Ø¼ü×ÖINSERTÖ¸Ã÷Á˼¤»î´¥·¢³ÌÐòµÄʼþ¡£ÔÚ±¾ÀýÖУ¬INSERTÓï¾ä½«µ¼Ö´¥·¢³ÌÐòµÄ¼¤»î¡£ÄãÒ²¿ÉÒÔΪDELETEºÍUPDATEÓï¾ä´´½¨´¥·¢³ÌÐò¡£
· ¸úÔÚFOR EACH ROWºóÃæµÄÓï¾ä¶¨ÒåÁËÿ´Î¼¤»î´¥·¢³ÌÐòʱ½«Ö´ÐеijÌÐò£¬¶ÔÓÚÊÜ´¥·¢Óï¾äÓ°ÏìµÄÿһÐÐÖ´ÐÐÒ»´Î¡£ÔÚ±¾ÀýÖУ¬´¥·¢µÄÓï¾äÊǼòµ¥µÄSETÓï¾ä£¬¸ºÔ𽫲åÈëamountÁеÄÖµ¼ÓÆðÀ´¡£¸ÃÓï¾ä½«ÁÐÒýÓÃΪNEW.amount£¬Òâ˼ÊÇ“½«Òª²åÈëµ½ÐÂÐеÄamountÁеÄÖµ”¡£
ÒªÏëʹÓô¥·¢³ÌÐò£¬½«ÀÛ¼ÓÆ÷±äÁ¿ÉèÖÃΪ0£¬Ö´ÐÐINSERTÓï¾ä£¬È»ºó²é¿´±äÁ¿µÄÖµ£º
mysql> SET @sum = 0;
mysql> INSERT INTO account VALUES(137,14.98),(141,1937.50),(97,-100.00);
mysql> SELECT @sum AS 'Total amount inserted';
+-----------------------+
| Total amount inserted |
+-----------------------+
| 1852.48  
Ïà¹ØÎĵµ£º
¹Ø¼ü×Ö: mysql6 mysql6ÏÂÔØ
×÷ΪһÃû¿ª·¢ÈËÔ±,ÎÒ¶ÔÂÌɫСÈí¼þÇéÓжÀÖÓ,ÒòΪÓÃÆðÀ´·½±ã¿ì½ÝÂï,±ãÓÚЯ´ø,Ò×ÓÚÔÚÑÝʾϵͳÖÐʹÓÃ,¿ª·¢Ê±¿ÉÁ¢¼´½øÈë״̬. £¨ÔÚ¸½¼þÖУ©
ÒÔÏÂÊÇÏêϸ˵Ã÷:
MySQL 6 ÂÌÉ«¾«¼ò°æ(BAT°æ±¾)
MySQL 6 Ö§³ÖÍâ¼ü,ÊÓͼ´æ´¢¹ý³Ì,ÊÂÎñµÈ¹¦ÄÜ(ÂÌÉ«¾« ......
mysqlÎļþµ¼ÈëÂÒÂëÎÊÌâµÄ½â¾ö£º
1 ÃüÁî²ì¿´×Ö·ûÉèÖá£
mysql> show variables like "%char%";
2 ½«²»ÊÇutf-8µÄ¶¼¸Ä³Éutf8¡£Ö»ÓÐfilesystem²»±ä;
| Variable_name | Value
&nb ......
Ë÷ÒýÓÃÓÚ¿ìËÙÕÒ³öÔÚij¸öÁÐÖÐÓÐÒ»Ìض¨ÖµµÄÐС£²»Ê¹ÓÃË÷Òý£¬MySQL±ØÐë´ÓµÚ1Ìõ¼Ç¼¿ªÊ¼È»ºó¶ÁÍêÕû¸ö±íÖ±µ½ÕÒ³öÏà¹ØµÄÐС£±íÔ½´ó£¬»¨·ÑµÄʱ¼äÔ½¶à¡£Èç¹û±íÖвéѯµÄÁÐÓÐÒ»¸öË÷Òý£¬MySQLÄÜ¿ìËÙµ½´ïÒ»¸öλÖÃÈ¥ËÑÑ°µ½Êý¾ÝÎļþµÄÖм䣬ûÓбØÒª¿´ËùÓÐÊý¾Ý¡£Èç¹ûÒ»¸ö±íÓÐ1000ÐУ¬Õâ±È˳Ðò¶ÁÈ¡ÖÁÉÙ¿ì100±¶¡£×¢ÒâÈç¹ûÄãÐèÒª·ÃÎÊ ......
Class.forName("com.mySQL.jdbc.Driver");
String strUrl="jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=GB2312";
String strUser="nuey";
String strPassword="password";
Connection conn=DriverManager.getCon ......
Êý¾Ý¿â²Ù×÷ÀࣺDBCommon.class.php
//---------------------------------------------------------------------
// MySQL Master/SlaveÊý¾Ý¿â¶Áд²Ù×÷Àà
//
// ¿ª·¢×÷Õß: heiyeluren
// °æ±¾ÀúÊ·:
// 2006-09-20 »ù±¾µ¥Êý¾Ý¿â²Ù×÷¹¦ÄÜ, 25 ¸ö½Ó¿Ú
// 2007-07-30 Ö§³Öµ ......