百度了很多,添加索引,inndob引擎,数据类型与主表一样,..都无效。有谁还有解决办法?
CREATE TABLE salesrecords(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,merchandiseid INT,merchandiseshortcutname VARCHAR(10),merchandisefullname VARCHAR(30),wholesalequantity INT NOT NULL DEFAULT '0',retailquantity INT NOT NULL DEFAULT '0',saledate DATE,INDEX (merchandiseid),FOREIGN KEY (merchandiseid,merchandiseshortcutname,merchandisefullname) REFERENCES merchandise(id,shortcutname,fullname) ON DELETE RESTRICT ON UPDATE CASCADE);
CREATE TABLE salesrecords(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,merchandiseid INT,merchandiseshortcutname VARCHAR(10),merchandisefullname VARCHAR(30),wholesalequantity INT NOT NULL DEFAULT '0',retailquantity INT NOT NULL DEFAULT '0',saledate DATE,INDEX (merchandiseid),FOREIGN KEY (merchandiseid,merchandiseshortcutname,merchandisefullname) REFERENCES merchandise(id,shortcutname,fullname) ON DELETE RESTRICT ON UPDATE CASCADE);
1.只能是inndob表;
2.内外键字段信息要一样。
INDEX (merchandiseid,merchandiseshortcutname,merchandisefullname)复合索引后也是150错误
`id` int(11) NOT NULL auto_increment,
`shortcutname` varchar(10) NOT NULL,
`fullname` varchar(30) NOT NULL,
`res` varchar(30) default NULL,
`stockquantity` int(11) NOT NULL default '0',
`price` int(11) NOT NULL default '0',
`wholesaleprice` int(11) default '0',
`retailprice` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312
类型也是一致的
要为merchandise创建复合索引????
merchandise表的这三个字段创建索引id,shortcutname,fullname