From 34a8472dfaf899dd05fe00ae61b283678817c502 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Tue, 8 Aug 2017 22:20:42 +0200 Subject: [PATCH] separate the locations and rent_prices tables This way it would be a bit easier to work with and it would make more sense in the payment history. --- sql/.vs/sql/v14/.ssms_suo | Bin 23552 -> 18432 bytes sql/sql/setup_02_create_table.sql | 15 +++++++++++---- sql/sql/setup_03_insert_data.sql | 18 +++++++++--------- sql/sql/setup_04_create_views.sql | 18 +++++++++--------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/sql/.vs/sql/v14/.ssms_suo b/sql/.vs/sql/v14/.ssms_suo index 15c1480faa0e671c28c7c38b8265aa40cf656114..cd7333df8e2f88fa80491ca6f0104fccf0553845 100644 GIT binary patch delta 606 zcmZqJ!Pqc?ae{#?0}Kc-FbD$Kj6nSF|Ns9WVaCah9M&5XDi|j*61Ohq6DngRw&K=!|lf#r;w*rv!$ zKB6Kpc?nm@&!|56E09#%T&m8@$P~t~xk_U@|KtWKAeL*F zDgqh-av2D76fxujVF{QMG5Mi|iL?nrJVP==5ko3NB2YXP$SY&W1k&XU#gp|c6DFrv zicFp$&oz0Se9$JVC5-MC3@!|=49*N@3{DKDKvI{%k--wkwgj?FfNVzwLm_ zAdu+*j1ylMgULNXJd+pLXmNoAbAVp9W|*AlAT@c3vJ7{`d9Wx08^e;xg(0Ss>@_9@ zN-*+IcC_C=*&)nfvZ0*JWC2N)$qsG}iyT-sA8>PE-0Tpsh>7fa5Pom{lhi5H#Dc~qG0xv+SF*{*v5ifWW!G6JL<-~=!Xc7>;+2BpCL!KH z>!gaMo_d1}tt!C*5K>RA1U|qi$srOFs#GB&Avh5f^%PaADpaWg!t9b#qsD1T`&P3% z@6EhVGxNTAo4-i&cj-l;h9O(SPKX&*it=i6b5mb6fn5H{t;A<^fywM8Yh=9L@{l@p zOC{u(9PNVV%$KwWJ~z!;gSeVD!yl$xZ7r&GD2QSVH|mW=^H;a}$LVeBWp_D?t4%0y z)yBc)20N_U6j-mQzLfZJfz@aLX4rY!3eWNFFU&NVC=)Ria@?Jd;GFv#*A(v5!_}pH znoQ!O8I#kn77jrESRF(n!xjO}1RNe;VL7r+yIP4%0whEf5=HS79|;lxbpf>iiJ>Kk zS{N-c(u!ILzXEzj@EtPt1kukAwe|do2qMp-*Z+fydT!C8c`KQsrwI1f}J z?3>{yaWbl_a6+kpYoe#@%uhCB-l90*iO4R99Hhi5x(8%&>4s$9w;j9@3T436E-*@o zNNoef!89PICjo#`8h4GtduG?~@ZX%9EtebUz>_YL*- zjU*@1(`qv7;exF^|1Mg%2<<&UnmZScNyv^oybx^#n-ZcH%w4$&d*lnS)M0^elt=14 zkoUvK9d`SGI-#lQ9t>JLJ2{apX_$dbREAS>Gh)aF;@A4=!BI(`@7=0`KR$}dXlh(b zrZVbbtm-aOXyN(y#H-u6un6ddCdsSQ#c9w*=fb-~F_PK;_B6NhIDb~XkcFpGQ$dQ| zps;Fk+h6{^QGeyP$3NeDWKN8g-Tw}#Q4A#VI4(|I1z$7A1D)@II8U?}Fx2Z)v{L z(S|<{Z2vZ>a*dhr3c;gp*RKwiseVSQhixs~kM*3_(t0tybh^g5U)oh8GHF)f??3f!aeX^u_kVhUh9RDh&)oyT-uk R4E>#r`&^UYaV54yehtp=8JhqA 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