diff --git a/sql/.vs/sql/v14/.ssms_suo b/sql/.vs/sql/v14/.ssms_suo index 15c1480..cd7333d 100644 Binary files a/sql/.vs/sql/v14/.ssms_suo and b/sql/.vs/sql/v14/.ssms_suo differ diff --git a/sql/sql/setup_02_create_table.sql b/sql/sql/setup_02_create_table.sql index be0bd24..44f17a8 100644 --- a/sql/sql/setup_02_create_table.sql +++ b/sql/sql/setup_02_create_table.sql @@ -130,7 +130,8 @@ if not exists (select * from sysobjects where name='rents') rent_date date default getdate(), payment_date date null, member_id int not null, - rent_price_id int not null + rent_price_id int not null, + location_id int not null constraint rent_pk primary key (rent_id) ); @@ -143,6 +144,7 @@ if not exists (select * from sysobjects where name='locations') location_name varchar(50) not null, city_id int not null, country_id int not null, + rent_price_id int not null constraint location_pk primary key (location_id) ); @@ -150,7 +152,6 @@ use marketdb; if not exists (select * from sysobjects where name='rent_prices') CREATE TABLE rent_prices ( rent_price_id int identity not null, - location_id int not null, rent_price money not null, constraint rent_price_pk primary key (rent_price_id) ); @@ -244,11 +245,17 @@ IF OBJECT_ID('dbo.[fk_ren_rent_price_id]', 'F') IS NULL go use marketdb; -IF OBJECT_ID('dbo.[fk_rpr_location_id]', 'F') IS NULL - ALTER TABLE rent_prices ADD CONSTRAINT fk_rpr_location_id +IF OBJECT_ID('dbo.[fk_ren_location_id]', 'F') IS NULL + ALTER TABLE rents ADD CONSTRAINT fk_ren_location_id FOREIGN KEY (location_id) REFERENCES locations (location_id); go +use marketdb; +IF OBJECT_ID('dbo.[fk_location_rpr_id]', 'F') IS NULL + ALTER TABLE locations ADD CONSTRAINT fk_location_rpr_id + FOREIGN KEY (rent_price_id) REFERENCES rent_prices (rent_price_id); +go + use marketdb; IF OBJECT_ID('dbo.[fk_loc_city_id]', 'F') IS NULL ALTER TABLE locations ADD CONSTRAINT fk_loc_city_id diff --git a/sql/sql/setup_03_insert_data.sql b/sql/sql/setup_03_insert_data.sql index ea66e06..ab8e509 100644 --- a/sql/sql/setup_03_insert_data.sql +++ b/sql/sql/setup_03_insert_data.sql @@ -4627,20 +4627,20 @@ values ('3946','Gruben',1), ('8238','Büsingen',1), ('9489','Schaan Log',1); +use marketdb; +insert into dbo.rent_prices (rent_price) +values (450), + (500); + use marketdb; insert into dbo.locations (streetname, location_capacity, location_name, city_id, - country_id) -values ('Markstrasse',300,'Testmarkt',5,1), - ('Teststrasse',450,'Testmark2',6,1); - -use marketdb; -insert into dbo.rent_prices (location_id, - rent_price) -values (1,450), - (2,500); + country_id, + rent_price_id) +values ('Markstrasse',300,'Testmarkt',5,1,1), + ('Teststrasse',450,'Testmark2',6,1,2); use marketdb; insert into dbo.persons (salutation_id, diff --git a/sql/sql/setup_04_create_views.sql b/sql/sql/setup_04_create_views.sql index 88803a2..215eb9f 100644 --- a/sql/sql/setup_04_create_views.sql +++ b/sql/sql/setup_04_create_views.sql @@ -9,12 +9,12 @@ use marketdb; go CREATE VIEW RentedLocations AS - SELECT dbo.locations.location_name, - dbo.locations.location_capacity, - dbo.rent_prices.rent_price, - dbo.rents.rent_date, - dbo.members.email_address - FROM dbo.members - INNER JOIN dbo.rents ON dbo.members.member_id = dbo.rents.member_id - INNER JOIN dbo.rent_prices ON dbo.rents.rent_price_id = dbo.rent_prices.rent_price_id - INNER JOIN dbo.locations ON dbo.rent_prices.location_id = dbo.locations.location_id \ No newline at end of file + SELECT dbo.locations.location_name, + dbo.locations.location_capacity, + dbo.rent_prices.rent_price, + dbo.rents.rent_date, + dbo.members.email_address + FROM dbo.members + INNER JOIN dbo.rents ON dbo.members.member_id = dbo.rents.member_id + INNER JOIN dbo.rent_prices ON dbo.rents.rent_price_id = dbo.rent_prices.rent_price_id + INNER JOIN dbo.locations ON dbo.rents.location_id = dbo.locations.location_id \ No newline at end of file