mysql¼¶ÁªÉ¾³ý Mysql µÄ Cascade Restrict
½ñÌìÓöµ½Êý¾Ý¿âµÄÒ»¸öÎÊÌ⣬¾ÍÊÇÿµ±´ÓÖ÷±íÖÐɾ³ýÒ»¸öÖ÷¼üidʱ£¬ÓÉÓÚÓëËûÏà¹ØÁªµÄ±íÖÐÓÐÏà¹ØµÄ×Ö¶ÎÊý¾Ý£¬ËùÒÔÎÞ·¨É¾³ý¡£²éÁËÒ»´ó¶Ñ×ÊÁÏ£¬·¢ÏÖÎÒ½¨±í¹ØÁªÓõÄÊÇon Restrict.¿ÉÄÜÎÊÌâ¾Í³öÔÚÕâÀï°É¡£
Íâ¼üÔ¼Êø¶Ô×Ó±íµÄº¬Òå:
Èç¹ûÔÚ¸¸±íÖÐÕÒ²»µ½ºòÑ¡¼ü,Ôò²»ÔÊÐíÔÚ×Ó±íÉϽøÐÐinsert/update
Íâ¼üÔ¼Êø¶Ô¸¸±íµÄº¬Òå:
ÔÚ¸¸±íÉϽøÐÐupdate/deleteÒÔ¸üлòɾ³ýÔÚ×Ó±íÖÐÓÐÒ»Ìõ»ò¶àÌõ¶ÔӦƥÅäÐеĺòÑ¡¼üʱ,¸¸±íµÄÐÐΪȡ¾öÓÚ£ºÔÚ¶¨Òå×Ó±íµÄÍâ¼üʱָ¶¨µÄon update/on delete×Ó¾ä, InnoDBÖ§³Ö£µÖÖ·½Ê½, ·ÖÁÐÈçÏÂ
. cascade·½Ê½
ÔÚ¸¸±íÉÏupdate/delete¼Ç¼ʱ£¬Í¬²½update/deleteµô×Ó±íµÄÆ¥Åä¼Ç¼
On delete cascade´Ómysql3.23.50¿ªÊ¼¿ÉÓÃ; on update cascade´Ómysql4.0.8¿ªÊ¼¿ÉÓÃ
. set null·½Ê½
ÔÚ¸¸±íÉÏupdate/delete¼Ç¼ʱ£¬½«×Ó±íÉÏÆ¥Åä¼Ç¼µÄÁÐÉèΪnull
ҪעÒâ×Ó±íµÄÍâ¼üÁв»ÄÜΪnot null
On delete set null´Ómysql3.23.50¿ªÊ¼¿ÉÓÃ; on update set null´Ómysql4.0.8¿ªÊ¼¿ÉÓÃ
. No action·½Ê½
Èç¹û×Ó±íÖÐÓÐÆ¥ÅäµÄ¼Ç¼,Ôò²»ÔÊÐí¶Ô¸¸±í¶ÔÓ¦ºòÑ¡¼ü½øÐÐupdate/delete²Ù×÷
Õâ¸öÊÇANSI SQL-92±ê×¼,´Ómysql4.0.8¿ªÊ¼Ö§³Ö
. Restrict·½Ê½
ͬno action, ¶¼ÊÇÁ¢¼´¼ì²éÍâ¼üÔ¼Êø
. Set default·½Ê½
½âÎöÆ÷ÈÏʶÕâ¸öaction,µ«Innodb²»ÄÜʶ±ð£¬²»ÖªµÀÊÇʲôÒâ˼£®£®£®
×¢Ò⣺trigger²»»áÊÜÍâ¼ücascadeÐÐΪµÄÓ°Ïì,¼´²»»á½â·¢trigger
ÔÚmysqlÖУ¬Óë£Ó£Ñ£Ì±ê×¼ÏàÎ¥±³µÄÈýµã
1. Èç¹ûÔÚ¸¸±íÖÐÓжà¸ökeyÖµÏàͬ£¬ÄÇôÔÚ½øÐÐÍâ¼ücheckʱ,»áµ±³ÉÓÐÏàͬkeyÖµµÄÆäËûÐв»´æÔÚ; ±ÈÈçµ±¶¨ÒåÁËÒ»¸örestrictÐÐΪÍâ¼üʱ,Ò»¸ö×Ó±íÐжÔÓ¦µ½¶à¸ö¸¸±íÐÐ(¾ßÓÐÏàͬkeyÖµ), Innodb²»ÔÊÐíɾ³ý¸¸±íÉϵÄËùÓÐÕâЩÐÐ
2. ¸¸×Ó±íÊÇͬһ¸ö±í,×ÔÎÒ²ÎÕÕʱ²»ÔÊÐíÖ¸¶¨on update cascade, on update set null
´Ómysql4.0.13¿ªÊ¼£¬ÔÊÐíͬһ¸ö±íÉϵÄon delete set null
´Ómysql4.0.21¿ªÊ¼£¬ÔÊÐíͬһ¸ö±íÉϵÄon delete cascade
µ«¼¶Áª²ã´Î²»
Ïà¹ØÎĵµ£º
http://dev.mysql.com/doc/refman/5.1/zh/partitioning.html
²é¿´ÊÇ·ñÖ§³Ö·ÖÇø£ºSHOW VARIABLES LIKE '%partition%';
·ÖÇøÓï¾äCREATE TABLE ti (id INT, amount DECIMAL(7,2), tr_date DATE)
ENGINE=INNODB
PARTITION BY HASH(MONTH(tr_date))
PARTITIONS 6;
---------------------------------- ......
phpºÍjavaͨÓÃsqlÓï¾ä·¨
SELECT max(id) from table
¸Ã·½·¨ÔÚ¶àÏ̵߳ÈÇé¿öÏ¿ÉÄÜ»áÔì³É²»ÕýÈ·¡£
javaÈýÖÖ·½·¨
1¡¢¸ù¾ÝpsµÄgetGeneratedKeys
PreparedStatement ps = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); //ºìÉ«Êǹؼü
ps.executeUpdate(); //Ö´Ðкó
ResultSet rs = ps.getGeneratedKeys ......
1 ÄÚ´æ±íµÄ±í»ú¹¹»¹ÊÇÔÚÊý¾Ý¿âÖеģ¬Ö»ÊÇÊý¾Ýʱ·ÅÔÚÄÚ´æÖеġ£
2 ÄÚ´æ±íÖв»¿ÉÒÔʹÓÃTEXTºÍBLOBÀàÐ͵Ä×ֶΡ£
3 ÄÚ´æ±í¿ÉÒÔͨ¹ýmax_heap_table_size = 2048MÀ´¼Ó´óʹÓõÄÄÚ´æ¡£
1 ÁÙʱ±íµÄ±í»ú¹¹ºÍÊý¾Ý¶¼ÊÇ·ÅÔÚÄÚ´æÖеÄ
¾ßÌå¼ûÏ£º
ÄÚ´æ±íʹÓùþϣɢÁÐË÷Òý°ÑÊý¾Ý±£´æÔÚÄÚ´æÖУ¬Òò´Ë¾ßÓм«¿ìµÄËٶȣ¬Êʺϻº´æÖÐСÐÍÊý¾Ý¿ ......
Ò»°ãÔÚMYSQLʹÓÃÖÐÎIJéѯ
¶¼ÊÇÓà set NAMES character
character_set_client £¬ÕâÊÇÓû§¸æËßMySQL²éѯÊÇÓõÄʲô×Ö·û¼¯¡£
character_set_connection £¬MySQL½ÓÊܵ½Óû§²éѯºó£¬°´ÕÕcharacter_set_client½«Æäת»¯Îªcharacter_set_connectionÉ趨µÄ×Ö·û¼¯¡£
character_set_results £¬ MySQL½«´æ´¢µÄÊý¾Ýת»»³Écharact ......
MySQL-client-community-5.0.41-0.rhel4.i386.rpm # ¿Í»§¶Ë
MySQL-devel-community-5.0.82-0.rhel4.i386.rpm   ......