mysql 设置外键关联sql语句

CREATE TABLE IF NOT EXISTS `book_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `groupon_shop_id` bigint(20) ,


  `no_rebate_detail` varchar(100) DEFAULT NULL,


  'rebate' float,
  `preferential_info` 


  `wap_detail_url` varchar(100) DEFAULT NULL,
  `detail_url` varchar(100) DEFAULT NULL,


  'img_path` varchar(100) DEFAULT NULL,
  'mobile_img_path` varchar(100) DEFAULT NULL,


  'create_date` datetime NOT NULL,
  'update_date` datetime DEFAULT NULL,
  'version` int(11) DEFAULT NULL,


  PRIMARY KEY (`id`),
  KEY `FK_BOOK_INFO_1` (`coupon_group_id`),


ALTER TABLE `book_info`
  ADD CONSTRAINT `FK_BOOK_INFO_1` FOREIGN KEY (`coupon_group_id`) REFERENCES `coupon_group` (`id`);

首先定义一个外键   KEY `FK_BOOK_INFO_1` (`coupon_group_id`),然后再用alert语句改变!



你可能感兴趣的:(mysql)