Skip to content

Instantly share code, notes, and snippets.

@SamsadSajid
Created December 29, 2021 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamsadSajid/619464b588afd5dc2d62cbbdd7c6aa5e to your computer and use it in GitHub Desktop.
Save SamsadSajid/619464b588afd5dc2d62cbbdd7c6aa5e to your computer and use it in GitHub Desktop.
Drop box sql schema
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