Created
December 29, 2021 13:51
-
-
Save SamsadSajid/619464b588afd5dc2d62cbbdd7c6aa5e to your computer and use it in GitHub Desktop.
Drop box sql schema
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
CREATE TABLE user( | |
user_id varchar(50) PRIMARY KEY, | |
name varchar(50) | |
); | |
CREATE TABLE devices( | |
device_id varchar(50) PRIMARY key, | |
user_id varchar(50) not null, | |
foreign key(user_id) references user(user_id) | |
); | |
CREATE TABLE objects( | |
object_id varchar(50), | |
device_id varchar(50), | |
PRIMARY key(object_id, device_id), | |
foreign key(device_id) references devices(device_id) | |
); | |
insert into user values('1', 'lol'); | |
insert into devices values('1', '1'); | |
insert into devices values('2', '1'); | |
insert into devices values('3', '1'); | |
insert into objects values('1', '1'); | |
insert into objects values('3', '1'); | |
insert into objects values('1', '2'); | |
select device_id from objects where object_id='1'; | |
select object_id from objects where device_id='1'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment