Commit fb0f9d55 authored by Michael Böhme's avatar Michael Böhme
Browse files

Upload New File

parent ecfb244f
create table employees
(employee_id smallint not null,
last_name varchar (20) not null,
first_name varchar (30) not null,
title varchar (30),
title_of_courtesy varchar(25),
birth_date date,
hire_date date,
address varchar(60),
city varchar(15),
region varchar(15),
postal_code varchar(10),
country varchar(15),
home_phone varchar(24),
extension_ varchar(4),
photo bytea,
notes text,
reports_to smallint,
photo_path varchar(255)
);
create table regions(
region_id integer,
region_hq_city varchar(40) not null
);
create table employee_regions(
employee_id smallint,
region_id integer
);
INSERT INTO regions
values (1,'Mainz'),(2,'Madrid'),(3,'Miami'),(4,'Rio De Janeiro');
ALTER TABLE ONLY employees
ADD CONSTRAINT pk_employees PRIMARY KEY (employee_id);
ALTER TABLE ONLY regions
ADD CONSTRAINT pk_regions PRIMARY KEY (region_id);
ALTER TABLE ONLY employee_regions
ADD CONSTRAINT pk_employee_regions PRIMARY KEY (employee_id, region_id);
ALTER TABLE ONLY employee_regions
ADD CONSTRAINT fk_employee_regions_employees FOREIGN KEY (employee_id) REFERENCES employees;
ALTER TABLE ONLY employee_regions
ADD CONSTRAINT fk_employee_regions_regions FOREIGN KEY (region_id) REFERENCES regions;
ALTER TABLE ONLY orders
ADD CONSTRAINT fk_orders_employees FOREIGN KEY (employee_id) REFERENCES employees;
insert into employee_regions (employee_id, region_id) values
(1,1),
(2,2),
(3,3),
(4,4),
(5,1),
(6,2),
(7,3),
(8,4),
(9,1);
ALTER TABLE employees
add column phone_number character varying(12);
UPDATE employees SET phone_number = '123456'
WHERE employee_id =(1);
UPDATE employees SET phone_number = '234567'
WHERE employee_id =(2);
UPDATE employees SET phone_number = '345678'
WHERE employee_id =(3);
UPDATE employees SET phone_number = '456789'
WHERE employee_id =(4);
UPDATE employees SET phone_number = '567890'
WHERE employee_id =(5);
UPDATE employees SET phone_number = '678901'
WHERE employee_id =(6);
UPDATE employees SET phone_number = '789012'
WHERE employee_id =(7);
UPDATE employees SET phone_number = '890123'
WHERE employee_id =(8);
UPDATE employees SET phone_number = '901234'
WHERE employee_id =(9);
alter table employees
add foreign key (reports_to) references employees(employee_id);
create index idx_employees_last_name on employees (last_name);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment