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

MYSQLÍâ¼ü(Foreign Key)µÄʹÓ㨶þ£©

×÷ÕߣºDirk (dirk.ye AT gmail.com)
Url£ºhttp://dirk.pdx.cn
ÈÕÆÚ£º2004/12/08
Ê×ÏÈ£¬Ä¿Ç°ÔÚ²úÆ·»·¾³¿ÉÓõÄMySQL°æ±¾£¨Ö¸4.0.xºÍ4.1.x£©ÖУ¬Ö»ÓÐInnoDBÒýÇæ²ÅÔÊÐíʹÓÃÍâ¼ü£¬ËùÒÔ£¬ÎÒÃǵÄÊý¾Ý±í±ØÐëʹÓÃ
InnoDBÒýÇæ¡£
ÏÂÃ棬ÎÒÃÇÏÈ´´½¨ÒÔϲâÊÔÓÃÊý¾Ý¿â
񡜧
CREATE TABLE `roottb` (
`id` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
`data` VARCHAR(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) TYPE=InnoDB;
CREATE TABLE `subtb` (
`id` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
`rootid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`data` VARCHAR(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
INDEX (`rootid`),
FOREIGN KEY (`rootid`) REFERENCES roottb(`id`) ON DELETE CASCADE
) TYPE=InnoDB;

×¢Ò⣺
1¡¢±ØÐëʹÓÃInnoDBÒýÇ棻
2¡¢Íâ¼ü±ØÐ뽨Á¢Ë÷Òý£¨INDEX£©£»
3¡¢Íâ¼ü°ó¶¨¹ØϵÕâÀïʹÓÃÁË“ ON DELETE
CASCADE”£¬Òâ˼ÊÇÈç¹ûÍâ¼ü¶ÔÓ¦Êý¾Ý±»É¾³ý£¬½«¹ØÁªÊý¾ÝÍêȫɾ³ý£¬¸ü¶àÐÅÏ¢Çë²Î¿¼MySQLÊÖ²áÖйØÓÚInnoDBµÄÎĵµ£»
ºÃ£¬½Ó×ÅÎÒÃÇÔÙÀ´²åÈë²âÊÔÊý¾Ý£º
INSERT INTO `roottb` (`id`,`data`)
VALUES ('1', 'test root line 1'),
('2', 'test root line 2'),
('3', 'test root line 3');
INSERT INTO `subtb` (`id`,`rootid`,`data`)
VALUES ('1', '1', 'test sub line 1 for root 1'),
('2', '1', 'test sub line 2 for root 1'),
('3', '1', 'test sub line 3 for root 1'),
('4', '2', 'test sub line 1 for root 2'),
('5', '2', 'test sub line 2 for root 2'),
('6', '2', 'test sub line 3 for root 2'),
('7', '3', 'test sub line 1 for root 3'),
('8', '3', 'test sub line 2 for root 3'),
('9', '3', 'test sub line 3 for root 3');
ÎÒÃÇÏÈ¿´Ò»Ïµ±Ç°Êý¾Ý±íµÄ״̬£º
mysql>; show tables;
+----------------+
| Tables_in_test |
+----------------+
| roottb |
| subtb |
+----------------+
2 rows in set (0.00 sec)
mysql>; select * from `roottb`;
+----+------------------+
| id | data |
+----+------------------+
| 1 | test root line 1 |
| 2 | test root line 2 |
| 3 | t


Ïà¹ØÎĵµ£º

Ó¦Ó÷ÃÎÊMysqlÓöµ½µÄÁ¬½ÓÎÊÌâ

×î½üÔÚ×öÒ»¸öСÏîÄ¿£¬¿ª·¢»·¾³£ºÊý¾Ý¿âmysql5.0£¬·þÎñÆ÷Tomcat5.5¡£ÏîÄ¿´ò³Éwar²¿ÊðÔÚtomcatÉÏÖ®ºó£¬Í¨¹ýÓ¦ÓýøÐвéѯ²Ù×÷£¬Èç¹û²Ù×÷¹ýÓÚƵ·±£¬ºǫ́»áÅ×ÈçÏÂÒì³££º
javax.servlet.ServletException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [08S01]; error co ......

MYSQLºÍORACLEµÄһЩ²Ù×÷Çø±ð

ÓкܶàÓ¦ÓÃÏîÄ¿, ¸ÕÆð²½µÄʱºòÓÃMYSQLÊý¾Ý¿â»ù±¾ÉÏÄÜʵÏÖ¸÷ÖÖ¹¦ÄÜÐèÇó£¬Ëæ×ÅÓ¦ÓÃÓû§µÄÔö¶à£¬Êý¾ÝÁ¿µÄÔö¼Ó£¬MYSQL½¥½¥µØ³öÏÖ²»¿°ÖظºµÄÇé¿ö£ºÁ¬½ÓºÜÂýÉõÖÁå´»ú£¬ÓÚÊǾÍÓаÑÊý¾Ý´ÓMYSQLǨµ½ORACLEµÄÐèÇó£¬Ó¦ÓóÌÐòÒ²ÒªÏàÓ¦×öһЩÐ޸ġ£±¾ÈË×ܽá³öÒÔϼ¸µã×¢ÒâÊÂÏϣÍû¶Ô´ó¼ÒÓÐËù°ïÖú¡£
1.×Ô¶¯Ôö³¤µÄÊý¾ÝÀàÐÍ´¦Àí
MYSQLÓÐ ......

mysql ×Ó²éѯɾ³ý¼Ç¼

    mysql ¿ÉÒÔͨ¹ý×Ó²éѯµÃµ½ÒªÉ¾³ýµÄ¼Ç¼Ìõ¼þ£¬È»ºóͨ¹ý×Ó²éѯµÃ½á¹ûÆ¥ÅäҪɾ³ýµÄ¼Ç¼¡£µ«ÊÇ mysql ²»ÄÜÖ±½Óɾ³ý×Ó²éѯ±íÖеÄÊý¾Ý£¬±ØÐëͨ¹ýÒ»¸öÁÙʱ±íÀ´½â¾ö¡£ÀýÈ磺
    delete from t_transaction where exists
    (select d.* from t_ti_category a,t_category b,t_ ......

LinuxÏÂMySQL5.1µÄ°²×°

×î½üÏëÔÚ·þÎñÆ÷ÉÏÊÔÊÔMySQL5.1µÄ·ÖÇø£¬ÓÚÊǾÍÏë×Å×°¸öMySQL5.1£¬¾­¹ýÍ´¿àµÄÒ»¶Î¾­Àúºó£¬ÖÕÓÚÕÒ¸öÏÂÃæ×°¸öºÜºÃµÄ½Ì³Ì£¬ÌûÉÏÀ´±¸Íü¡£
1¡¢MySQLÃâ°²×°°æ/¶þ½øÖÆ°æÈí¼þ£¬²»ÓñàÒ룬ÏÂÔصØÖ·£º
     http://dev.mysql.com/downloads/
     Îļþ¸ñʽ£ºMYSQL-VERSION-OS.tar.gz
2¡¢´ ......

MySQL Basic Knowledge

MySQL°æ±¾: Server version: 5.1.44 Source distribution
ÐÞ¸ÄrootÃÜÂë
Èç¹ûûÓÐÃÜÂëʹÓÃÏÂÃæµÄÃüÁî, ½«ÃÜÂëÉèΪ"123456"
$ mysqladmin -u root password 123456
Èç¹ûÓÐÃÜÂëʹÓÃÏÂÃæµÄÃüÁî, ½«ÃÜÂë¸ÄΪ"123456"
$ mysqladmin -u root -p password 123456
Enter password:
Óû§ÕË»§¹ÜÀí
Ìí¼ÓÕË» ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ