Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE foo ( x int PRIMARY KEY );
- CREATE TABLE bar (
- x int,
- CONSTRAINT asdf FOREIGN KEY (x) REFERENCES foo(x)
- );
- MariaDB [test]> DROP TABLE foo;
- ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
- # CREATE TABLE foo ( x int PRIMARY KEY );
- # CREATE TABLE bar ( x int REFERENCES foo );
- # DROP TABLE foo CASCADE;
- NOTICE: drop cascades to constraint bar_x_fkey on table bar
- DROP TABLE
- CREATE TABLE foo
- (
- x int PRIMARY KEY
- );
- CREATE TABLE bar
- (
- x int,
- CONSTRAINT asdf FOREIGN KEY (x) REFERENCES foo(x) ON DELETE CASCADE
- );
- INSERT INTO foo VALUES (3), (45), (7);
- INSERT INTO bar VALUES(3), (3), (45), (7), (7);
- DELETE FROM foo WHERE x = 3;
- SELECT * FROM bar;
- x
- 7
- 7
- 45
- ERROR: cannot drop table foo because other objects depend on it
- DETAIL: constraint asdf on table bar depends on table foo
- HINT: Use DROP ... CASCADE to drop the dependent objects too
- DROP TABLE foo CASCADE;
Add Comment
Please, Sign In to add comment