Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CREATE TABLE employee (id int not null, first_name text not null, last_name text not null, primary key(id));
CREATE TABLE employee_department (id int not null, name text not null, description text not null, primary key(id));
ALTER TABLE
employee_employee.employeeADD COLUMN
department_IDint(11) NOT NULL;ALTER TABLE
employee_employee.employeeDROP PRIMARY KEY,
ADD PRIMARY KEY (
id,department_ID) ;ALTER TABLE
employee_employee.employeeADD INDEX
employee_department_fk_1_idx(department_IDASC);ALTER TABLE
employee_employee.employeeADD CONSTRAINT
employee_department_fk_1FOREIGN KEY (
department_ID)REFERENCES
employee_employee.employee_department(id);CREATE TABLE employee_hobby (id int not null, name text NOT NULL, description text not null, primary key(id));
ALTER TABLE
employee_employee.employeeADD COLUMN
Hobby_1_IDINT(11) NOT NULL,DROP PRIMARY KEY,
ADD PRIMARY KEY (
id,department_ID,Hobby_1_ID);ALTER TABLE
employee_employee.employeeADD COLUMN
Hobby_2_IDINT(11) NOT NULL,DROP PRIMARY KEY,
ADD PRIMARY KEY (
id,department_ID,Hobby_2_ID);ALTER TABLE
employee_employee.employeeADD CONSTRAINT
employee_hobby_fk_1FOREIGN KEY (
Hobby_1_ID)REFERENCES
employee_employee.employee_hobby(id)ON DELETE NO ACTION
ON UPDATE NO ACTION;
ALTER TABLE
employee_employee.employeeADD CONSTRAINT
employee_hobby_fk_2FOREIGN KEY (
Hobby_2_ID)REFERENCES
employee_employee.employee_hobby(id)ON DELETE NO ACTION
ON UPDATE NO ACTION;
INSERT INTO
employee_employee.employee_hobby(id,description,name) VALUES ('1', 'arts', 'painting');INSERT INTO
employee_employee.employee_hobby(id,description,name) VALUES ('2', 'cooking', 'cooking');INSERT INTO
employee_employee.employee_hobby(id,description,name) VALUES ('3', 'sports', 'exercising');INSERT INTO
employee_employee.employee_department(id,name,description) VALUES ('1', 'H.R.', 'Human resources');INSERT INTO
employee_employee.employee_department(id,name,description) VALUES ('2', 'Sales', 'Sales');INSERT INTO
employee_employee.employee_department(id,name,description) VALUES ('3', 'Development', 'Software development');INSERT INTO
employee_employee.employee_department(id,name,description) VALUES ('4', 'Technical support', 'Technical support');INSERT INTO
employee_employee.employee_department(id,name,description) VALUES ('5', 'Front Desk', 'Front desk');INSERT INTO
employee_employee.employee_department(id,name,description) VALUES ('6', 'Warehouse', 'Warehouse, supplies');INSERT INTO
employee_employee.employee(id,first_name,last_name,department_ID,Hobby_1_ID,Hobby_2_ID) VALUES ('1', 'Aldo', 'Serrano', '1', '2', '1');INSERT INTO
employee_employee.employee(id,first_name,last_name,department_ID,Hobby_1_ID,Hobby_2_ID) VALUES ('2', 'Marcela', 'Luna', '3', '3', '1');INSERT INTO
employee_employee.employee(id,first_name,last_name,department_ID,Hobby_1_ID,Hobby_2_ID) VALUES ('3', 'isai', 'rodriguez', '1', '1', '2');INSERT INTO
employee_employee.employee(id,first_name,last_name,department_ID,Hobby_1_ID,Hobby_2_ID) VALUES ('4', 'marcos', 'sanchez', '1', '2', '1');INSERT INTO
employee_employee.employee(id,first_name,last_name,department_ID,Hobby_1_ID,Hobby_2_ID) VALUES ('5', 'helena', 'perez', '2', '2', '3');INSERT INTO
employee_employee.employee(id,first_name,last_name,department_ID,Hobby_1_ID,Hobby_2_ID) VALUES ('6', 'fabiola', 'torres', '3', '3', '2');