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.
This commit is contained in:
parent
d210e1522e
commit
34a8472dfa
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
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
|
Loading…
Reference in New Issue