/* Tabeller til oppgave 1 uke 9 */ drop table Ansatt cascade; drop table Avdeling cascade; drop table Prosjekt cascade; drop table Prosjektplan cascade; create table Ansatt ( anr serial primary key, navn varchar (250) not null, l?nn int not null, avdnr int ); create table Avdeling ( avdnr serial primary key, anavn varchar (250) not null, leder int ); create table Prosjekt ( pnr serial primary key, pnavn varchar (250) not null, unique(pnavn) ); create table Prosjektplan ( pnr int references Prosjekt (pnr), anr int references Ansatt (anr), timer int, primary key (pnr, anr) ); alter table avdeling add constraint FK_Avdeling_leder foreign key (leder) references Ansatt (anr); alter table ansatt add constraint FK_Ansatt_avdnr foreign key (avdnr) references Avdeling (avdnr); /* Data til oppgave 1 uke 9 */ insert into prosjekt values (default, 'ProsjektX'); insert into prosjekt values (default, 'ProsjektY'); insert into prosjekt values (default, 'Aksjeb?rs'); insert into avdeling values (default, 'Salg', NULL); insert into avdeling values (default, 'Utvikling', NULL); insert into avdeling values (default, '?konomi', NULL); insert into avdeling values (default, 'Administrasjon', NULL); insert into ansatt values (default, 'Kari Nilsen', 400000, 1); insert into ansatt values (default, 'K?re Hansen', 520000, 4); insert into ansatt values (default, 'Ole Olsen', 490000, 2); insert into ansatt values (default, 'Stein Pettersen', 490000, 2); insert into ansatt values (default, 'Cathrine Monsen', 490000, 2); insert into ansatt values (default, 'Silje A. Olsen', 400000, 2); insert into prosjektplan values (3, 4, 132); insert into prosjektplan values (3, 1, 58); insert into prosjektplan values (1, 1, 34); insert into prosjektplan values (2, 1, 22); insert into prosjektplan values (1, 4, 14); insert into prosjektplan values (2, 6, 122); insert into prosjektplan values (2, 5, 122); insert into prosjektplan values (3, 5, 76); insert into prosjektplan values (1, 3, 12); insert into prosjektplan values (3, 3, 50); /* Tabeller til oppgave 2 uke 9 */ drop view Gjesteliste; drop view Regningsliste; drop table Bestilling; drop table Gjest; drop table Rom; drop table Hotell; CREATE table Hotell ( hotellnr int primary key, hotellnavn varchar (100) not null, by varchar (50) not null, unique(hotellnavn, by) ); CREATE table Rom ( romnr int, hotellnr int references Hotell (hotellnr), type varchar(100) not null, pris real not null, primary key (romnr, hotellnr) ); CREATE table Gjest ( gjestnr int primary key, gjestnavn varchar(200) not null, gjestadresse varchar(300) not null ); CREATE table Bestilling ( hotellnr int not null, romnr int not null, fradato date not null, tildato date not null check(tildato > fradato), gjestnr int references Gjest (gjestnr) not null, primary key (hotellnr, romnr, fraDato), foreign key (hotellnr, romnr) references Rom (hotellnr, romnr) ); /* Data til oppgave 2 uke 9 */ INSERT INTO Hotell(hotellnr, hotellnavn, by) VALUES (1, 'Oslo Plaza', 'Oslo'); /* N?r man fyller inn alle kolonner trenger man ikke oppgi navn p? attributtene s? lenge de oppgis i samme rekkef?lge som de er definert: */ INSERT INTO Hotell VALUES (2, 'SAS-hotellet', 'Oslo'); INSERT INTO Hotell VALUES (3, 'Hotell Opera', 'Oslo'); INSERT INTO Hotell VALUES (4, 'Norlandia', 'Bergen'); INSERT INTO Hotell VALUES (5, 'Hotel Norge', 'Bergen'); INSERT INTO Hotell VALUES (6, 'Radisson SAS Royal Garden', 'Trondheim'); INSERT INTO Hotell VALUES (7, 'Britannia Hotel', 'Trondheim'); /* Legge inn Rom-data */ INSERT INTO Rom VALUES (100, 1, 'dobbel', 499.00); INSERT INTO Rom VALUES (101, 1, 'dobbel', 499.00); INSERT INTO Rom VALUES (102, 1, 'familie', 699.00); INSERT INTO Rom VALUES (302, 1, 'enkel', 699.00); INSERT INTO Rom VALUES (146, 6, 'dobbel', 499.00); INSERT INTO Rom VALUES (148, 6, 'enkel', 699.00); INSERT INTO Rom VALUES (1241, 4, 'enkel', 1299.00); /* Legge inn data om gjester */ INSERT INTO Gjest VALUES (1, 'Hans Hansen', 'Kroken 4, 0481 Oslo'); INSERT INTO Gjest VALUES (2, 'Anne Hansen', 'Kroken 4, 0481 Oslo'); INSERT INTO Gjest VALUES (3, 'Ole Olsen', 'Nyveien 67, 7012 Trondheim'); /* Legge inn data om bestillinger */ INSERT INTO Bestilling VALUES (1, 101, date '2007-10-15', date '2007-10-22', 1); INSERT INTO Bestilling VALUES (1, 102, date '2007-10-15', date '2007-10-22', 2); INSERT INTO Bestilling VALUES (1, 302, date '2007-12-12', date '2007-12-13', 3); INSERT INTO Bestilling VALUES (6, 148, date '2007-10-28', date '2007-10-30', 3); INSERT INTO Bestilling VALUES (4, 1241, date '2007-12-12', date '2007-12-13', 3);