Skip to content

Instantly share code, notes, and snippets.

@morgo
Created February 18, 2017 18:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save morgo/d103bff2763d038fa9573c061f5b7bbc to your computer and use it in GitHub Desktop.
create table department (
id bigint not null,
budget bigint not null,
name varchar(255),
primary key (id)
) ENGINE=InnoDB;
create table employee (
id bigint not null,
name varchar(255),
salary bigint not null,
department_id bigint, primary key (id)
) ENGINE=InnoDB;
alter table employee
add constraint FK_department_id
foreign key (department_id)
references department (id);
insert into department (name, budget, id)
values ('Hypersistence', 100000, 1);
insert into department (name, budget, id)
values ('Bitsystem', 10000, 2);
insert into department (name, budget, id)
values ('XX', 10000, 3);
insert into employee (department_id, name, salary, id)
values (1, 'John Doe 0', 30000, 0);
insert into employee (department_id, name, salary, id)
values (1, 'John Doe 1', 30000, 1);
insert into employee (department_id, name, salary, id)
values (2, 'John Doe 2', 30000, 2);
start transaction;
SELECT *
FROM employee
WHERE department_id = 1
FOR UPDATE;
# new session
insert into employee (department_id, name, salary, id)
values (3, 'Dave', 9000, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment