Commit 4555f547 authored by Andreas Amberger's avatar Andreas Amberger
Browse files

Upload New File

parent ecfb244f
-- Datenbanken bung 3
-- Aufgabe 1:
create table employees (
employee_id smallint not null primary key,
last_name character varying(20) not null,
first_name character varying(30) not null,
title character varying(30),
title_of_courtesy character varying(25),
birth_date date,
hire_date date,
address character varying(60),
city character varying(15),
region character varying(15),
postal_code character varying(10),
country character varying(15),
home_phone character varying(24),
extension character varying(4),
photo bytea,
notes text,
reports_to smallint references employees (employee_id),
photo_path character varying(255)
);
create table regions (
region_id integer primary key,
region_headquarters_city character varying(40) not null
);
create table employee_regions(
employee_id smallint not null references employees (employee_id),
region_id integer not null references regions (region_id),
constraint pk_employee_regions primary key (employee_id, region_id)
);
-- Aufgabe 2.1
insert into regions (region_id, region_headquarters_city) values (1, 'Mainz');
insert into regions (region_id, region_headquarters_city) values (2, 'Madrid');
insert into regions (region_id, region_headquarters_city) values (3, 'Miami');
insert into regions (region_id, region_headquarters_city) values (4, 'Rio de Janeiro');
-- Aufgabe 2.2 --> reports_to als FK entfernen
alter table employees drop constraint fk_employees_employees;
-- Aufgabe 2.2 --> reports_to wieder zum FK machen
alter table only employees
add constraint fk_employees_employees foreign key (reports_to) references employees;
-- Verknuepfung Tabelle employees mit orders
alter table orders add constraint fk_orders_employee foreign key (employee_id) references employees;
-- Aufgabe 2.3
insert into employee_regions (employee_id, region_id) values
(1,1),
(2,2),
(3,3),
(4,4),
(5,1),
(6,2),
(7,3),
(8,1),
(9,2);
-- Aufgabe 2.4
alter table employees add column mobilePhoneNumber character varying(24);
update employees set mobilephonenumber = '0123456789';
-- Aufgabe 3
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