mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
@ -14,3 +14,40 @@ ALTER TABLE `title` ADD FOREIGN KEY (`title_manager_fk`) REFERENCES `people`
|
||||
ALTER TABLE `title` ADD FOREIGN KEY (`title_reporter_fk`) REFERENCES `people`
|
||||
(`people_id`);
|
||||
drop table title, department, people;
|
||||
create table t1 (a int primary key, b int) engine=innodb;
|
||||
create table t2 (c int primary key, d int,
|
||||
foreign key (d) references t1 (a) on update cascade) engine=innodb;
|
||||
insert t1 values (1,1),(2,2),(3,3);
|
||||
insert t2 values (4,1),(5,2),(6,3);
|
||||
flush table t2 with read lock;
|
||||
connect con1,localhost,root;
|
||||
delete from t1 where a=2;
|
||||
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE)
|
||||
update t1 set a=10 where a=1;
|
||||
connection default;
|
||||
unlock tables;
|
||||
connection con1;
|
||||
connection default;
|
||||
lock table t2 write;
|
||||
connection con1;
|
||||
delete from t1 where a=2;
|
||||
connection default;
|
||||
unlock tables;
|
||||
connection con1;
|
||||
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE)
|
||||
connection default;
|
||||
unlock tables;
|
||||
disconnect con1;
|
||||
create user foo;
|
||||
grant select,update on test.t1 to foo;
|
||||
connect foo,localhost,foo;
|
||||
update t1 set a=30 where a=3;
|
||||
disconnect foo;
|
||||
connection default;
|
||||
select * from t2;
|
||||
c d
|
||||
5 2
|
||||
4 10
|
||||
6 30
|
||||
drop table t2, t1;
|
||||
drop user foo;
|
||||
|
Reference in New Issue
Block a user