Skip to content

Instantly share code, notes, and snippets.

@makeittotop
Created September 5, 2016 09:20
Show Gist options
  • Save makeittotop/752a0d31e5b4a10b8468fb31ccc7f19d to your computer and use it in GitHub Desktop.
Save makeittotop/752a0d31e5b4a10b8468fb31ccc7f19d to your computer and use it in GitHub Desktop.
mysql create view alter table dump
create table employees(
employee_id INT NOT NULL AUTO_INCREMENT,
employee_title VARCHAR(100) NOT NULL,
employee_author VARCHAR(40) NOT NULL,
submission_date DATE,
PRIMARY KEY ( employee_id )
);
create table titles (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
PRIMARY KEY(id)
) ENGINE=InnoDb;
INSERT INTO titles (title) values ('foo');
INSERT INTO titles (title) values ('bar');
INSERT INTO titles (title) values ('buzz');
alter table employees add title_id int not null;
alter table employees add constraint employees_titles_title_id
foreign key (`title_id`)
references `titles` (`id`);
create view employee_position as
select employee.employee_id as employee_id,
employee_title,
employee_author,
submission_date,
title
from employees
left join titles on employees.title_id=titles.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment