Created
July 8, 2022 13:56
-
-
Save pimeys/bfce92e43cdc667b59625297f083a9b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- two schemas | |
create schema [janEatsHisHat]; | |
create schema [juliusQuitsHisJob]; | |
-- this one in the first schema, it's the "parent" table | |
create table [janEatsHisHat].[delicious] (id int primary key); | |
-- this one in the second, the "child" table | |
create table [juliusQuitsHisJob].[arbeitsamt] ( | |
id int primary key, | |
hat int, | |
constraint amt_hat_fk foreign key (hat) references [janEatsHisHat].[delicious](id) on delete cascade | |
); | |
-- three parents | |
insert into [janEatsHisHat].[delicious] (id) values (1), (2), (3); | |
-- two children referencing one of the parents each | |
insert into [juliusQuitsHisJob].[arbeitsamt] (id, hat) values (1, 1), (2, 2), (3, 3); | |
-- lists three parents | |
select * from [janEatsHisHat].[delicious]; | |
-- lists three children | |
select * from [juliusQuitsHisJob].[arbeitsamt]; | |
-- a parent gets deleted | |
delete from [janEatsHisHat].[delicious] where id = 1; | |
-- lists two children | |
select * from [juliusQuitsHisJob].[arbeitsamt]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment