Commit b388b0e7 authored by Thomas Klauer's avatar Thomas Klauer
Browse files

Merge branch 'undefined' into 'master'

peter-lukas

See merge request thomasklauer/datenbanken-ss20!7
parents dda9f23b 461d2af1
-- Tabellen erstellen
create table employees (
employee_id int NOT NULL,
last_name char(20) NOT NULL,
first_name char(30) NOT NULL,
title char(30),
title_of_courtesy char(25),
birth_date date,
hire_date date,
address char(60),
city char(15),
region char(15),
postal_code char(10),
country char(15),
home_phone char(24),
extension char(4),
photo bytea,
notes text,
reports_to int,
photo_path char(255)
);
create table employee_regions (
employee_id int not null,
region_id int
);
create table regions (
region_id int,
region_headquarter_city char(40) not null
);
-- Primrschlssel festlegen
alter table employees
add CONSTRAINT pk_employee_id PRIMARY KEY (employee_id); --Primrschlssel auf der Spalte employee_id
alter table employee_regions
add CONSTRAINT pk_employee_regions_id primary KEY (employee_id, region_id); --Primrschlssel auf der Spalte employee_id, region_id
alter table regions
add CONSTRAINT pk_regions_id PRIMARY KEY (region_id); --Primrschlssel auf der Spalte region_id
--> erst obigen Code ausfhren
--> dann employees.csv importieren
--> dann unteren Teil des Codes ausfhren
-- Fremdschlssel festlegen
alter table employees
add CONSTRAINT fk_reports_to FOREIGN KEY (reports_to) REFERENCES employees(employee_id); --Fremdschlssel auf der Spalte reports_to aus employee_id
alter table employee_regions
add CONSTRAINT fk_employee_regions_employee_id FOREIGN KEY (employee_id) REFERENCES employees, -- Fremdschlssel auf der Spalte employee_id aus employees
add CONSTRAINT fk_employee_regions_region_id FOREIGN KEY (region_id) REFERENCES regions; -- Fremdschlssel auf der Spalte region_id aus regions
--Tabelle regions fllen
insert into regions
values
(1, 'Mainz'), -- 1->region_id, Mainz->region_headquarter_city
(2, 'Madrid'),
(3, 'Miami'),
(4, 'Rio de Janeiro');
--Fremdschlssel festlegen
alter table orders
add CONSTRAINT fk_orders_employee_id FOREIGN KEY (employee_id) REFERENCES employees; -- Fremdschlssel auf der Spalte employee_id aus employees
--Attribut MobilePhoneNumber hinzufgen und fllen
alter table employees
add column mobile_phonenumber char(24);
update employees set mobile_phonenumber ='(206) 555-9857' where employee_id = 1;
update employees set mobile_phonenumber ='(206) 555-9482' where employee_id = 2;
update employees set mobile_phonenumber ='(206) 555-3412' where employee_id = 3;
update employees set mobile_phonenumber ='(206) 555-8122' where employee_id = 4;
update employees set mobile_phonenumber ='(71) 555-4848' where employee_id = 5;
update employees set mobile_phonenumber ='(71) 555-7773' where employee_id = 6;
update employees set mobile_phonenumber ='(71) 555-5598' where employee_id = 7;
update employees set mobile_phonenumber ='(206) 555-1189' where employee_id = 8;
update employees set mobile_phonenumber ='(71) 555-4444' where employee_id = 9;
--Index erstellen
create index idx_last_name on employees (last_name);
\ No newline at end of file
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