Commit 1e174cd9 authored by Thomas Klauer's avatar Thomas Klauer

Merge branch 'undefined' into 'master'

uebung3.2-3.3

See merge request thomasklauer/datenbanken-ss20!13
parents 1c8d972b f8e5e0fb
--
-- Name: employees; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE employees (
employee_id smallint not null,
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,
photo_path character varying(255)
);
--
-- Name: regions; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
create table regions (
region_id integer,
region_headquarter_city character varying(40) not null
);
--
-- Name: regions; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
create table employee_regions(
employee_id smallint not null,
region_id smallint not null
);
--Tabelle fllen
INSERT INTO regions VALUES (1,'Mainz');
INSERT INTO regions VALUES (2, 'Madrid');
INSERT INTO regions VALUES (3, 'Miami');
INSERT INTO regions VALUES (4, 'Rio de Janeiro');
--Erstellen der Primary Key
ALTER TABLE ONLY employees
ADD CONSTRAINT pk_employee_id 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);
--Erstellen der Fremdschlssel
ALTER TABLE ONLY employees
ADD CONSTRAINT fk_employee_reports_to FOREIGN KEY (reports_to) REFERENCES employees;
ALTER TABLE ONLY employee_regions
ADD CONSTRAINT fk_region_id FOREIGN KEY (region_id) REFERENCES regions;
ALTER TABLE ONLY employee_regions
ADD CONSTRAINT fk_employee_id FOREIGN KEY (employee_id) REFERENCES employees;
ALTER TABLE ONLY employee_regions
ADD CONSTRAINT fk_employee_id_employee FOREIGN KEY (employee_id) REFERENCES employees;
ALTER TABLE ONLY employee_regions
ADD CONSTRAINT fk_region_id_region FOREIGN KEY (region_id) REFERENCES regions (region_id);
ALTER TABLE ONLY orders
ADD CONSTRAINT fk_employee_id_orders FOREIGN KEY (employee_id) REFERENCES employees;
--Tabelle ergnzen
alter table only employees
add column MobilePhoneNumber character varying(24);
update employees set mobilephonenumber = 0123456789;
create index idx_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