0
我在刪除級聯有問題。MySql刪除級聯
drop table orders;
CREATE TABLE orders(
o_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
c_id INTEGER NOT NULL REFERENCES Customer(c_id),
a_id INTEGER NOT NULL REFERENCES Address(a_id),
order_date DATE NOT NULL,
value DECIMAL(10,2) NOT NULL CHECK (value >= 0.00),
method VARCHAR(20),
order_type VARCHAR(30),
order_interval VARCHAR(20),
start_date DATE NOT NULL,
admin VARCHAR(30),
active INTEGER NOT NULL,
notes VARCHAR(300)
);
drop table order_details;
CREATE TABLE order_details(
o_id INTEGER NOT NULL REFERENCES orders(o_id) ON DELETE CASCADE,
wp_id INTEGER NOT NULL REFERENCES wp_details(wp_id),
pack_revision INTEGER NOT NULL,
pack_order INTEGER NOT NULL,
delivery_date DATE NOT NULL,
dispatched_date DATE NOT NULL,
qty INTEGER NOT NULL,
f_id INTEGER REFERENCES freebies(f_id),
notes VARCHAR(300),
CONSTRAINT PRIMARY KEY (wp_id, o_id)
);
當我從訂單中刪除一個條目,它不會從order_details表中刪除。我的表格定義是否錯誤?
請確保您創建表爲InnoDB,因爲MyISAM不支持參考完整性。我不確定MySQL是否在使用'REFERENCES'時自動執行它。 – 2012-03-11 13:52:37
關注@AndrésGattinoni評論,請使用「show create table order_details」查看存儲引擎。它應該是InnoDB。 http://stackoverflow.com/questions/511361/how-do-i-use-on-delete-cascade-in-mysql – aingram 2012-03-11 21:05:04