网络表
"CREATE TABLE network("
. "n_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"
. "nname VARCHAR(50) NOT NULL,"
. "ndate DATE NOT NULL"
. ");";
位置表
"CREATE TABLE locality("
."l_id int NOT NULL AUTO_INCREMENT PRIMARY KEY,"
."lname varchar(50) NOT NULL,"
."ldate varchar(50) NOT NULL,"
."n_id int NOT NULL,"
. "CONSTRAINT locality_fk_1 FOREIGN KEY (n_id) REFERENCES network(n_id)ON DELETE CASCADE ON UPDATE CASCADE"
. ");";
从评论中添加:
它给我一个以下错误:
网络未删除无法删除或更新父行:外键约束失败(accelore.locality,CONSTRAINT locality_ibfk_1 FOREIGN KEY(n_id)REFERENCES network(n_id))
答案 0 :(得分:0)
您添加了外键约束,因此不会直接删除,您必须先删除约束
alter table locality drop constraint locality_ibfk_1
将删除约束,您可以删除网络或
如果您只想删除表中的数据,请使用:
delete from network where n_id = n_id;
将删除表中的所有数据而不删除任何表。或
如果您使用特定的n_id
,则delete
表中的特定数据。