From 7ba52b07ce21c2c5a55375bea4ee13d071ea386a Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 26 Jun 2017 21:18:21 +0200 Subject: [PATCH] add all the required constraints in addition I've fixed some minor bugs. --- sql/.vs/sql/v14/.ssms_suo | Bin 17920 -> 18944 bytes sql/sql/setup_02_create_table.sql | 128 +++++++++++++++++++++++++++--- 2 files changed, 116 insertions(+), 12 deletions(-) diff --git a/sql/.vs/sql/v14/.ssms_suo b/sql/.vs/sql/v14/.ssms_suo index 7cce9cbcc4c86ff11d384feccccb75af45742ead..43100da05f4c894cce1522fc95a676332f13de89 100644 GIT binary patch delta 1535 zcmb_bO>7fa5Pq|EHXE}xP7}u_{Me0AnjkFy#EGz4H(qaksFIRZ6x5z{9DP+H&fl7sB2+5rISmhej0=v^{a*RP|CvMUfz#S@N?@Ir3Js@4fk- z`Q}xwL**9SNE{a1%P&MDoq_1h=H@1|0X600<%vb8O2gp852dhg?uqf^oxgsC11$IB zCFwKNT}iCTYbqIS))AL?guqd`n=Yn=8?I4rfR607h4vtxaUTq{(J4yA+S}`hbxpZw z2Wzy0B_8~7j)SSBm*ZfUAcyPn*D!`lt|67#&VbN^>-FIS4aBY|Qi%2u$wVC6gE8d` zXs4Q*svh_9*c4Pf4AkUFUm2hq7u2he#`X3QyEGSxIZ-YRx~v87 zDZmFoD&1$OA(C;4+j2DbKUMg`iw)598!GoY=+LrienY}OR|3r@L*>@^98$cWbxZSr z8y}rgS{?klqjVX#PB+pGKZ4{ZZthsxfOOkTPaz!W*?xG%Hu=t zCsrjiD7P+>3ggeD%!^t2O#5;cUmQu}?^-+F`P7Y>@M-H-*e?yH#ehhOq|ilP^oTwY zqkl$dbdQO&NQf@`lp&owQH&&M(nyOFqMvrQOwrzjS0bICXDH@nlD!{~#kL<{$bx7u zSUHbN@&cFCOtjN3Q(d!L!b7yn^j@!aocw>gGw*7*VUGn*+pc|Z3|BjkJKIjrYH! z_X3Zs$Dv`>Lf^`D3E~I~!;R8ll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_table.sql +++ b/sql/sql/setup_02_create_table.sql @@ -6,6 +6,8 @@ -- Datum: 2017-06-05 -- Server Version: SQL Server 2016 + +-- create table use marketdb; if not exists (select * from sysobjects where name='commercials') CREATE TABLE commercials ( @@ -24,16 +26,16 @@ if not exists (select * from sysobjects where name='member_status') ); use marketdb; -if not exists (select * from sysobjects where name='salutation') - CREATE TABLE salutation ( +if not exists (select * from sysobjects where name='salutations') + CREATE TABLE salutations ( salutation_id int not null, salutation_name varchar(50) not null, constraint salutation_pk primary key (salutation_id) ); use marketdb; -if not exists (select * from sysobjects where name='subscription') - CREATE TABLE subscription ( +if not exists (select * from sysobjects where name='subscriptions') + CREATE TABLE subscriptions ( subscription_id int not null, max_rented_locations int not null, subscription_price money not null, @@ -43,8 +45,8 @@ if not exists (select * from sysobjects where name='subscription') ); use marketdb; -if not exists (select * from sysobjects where name='subscption_order') - CREATE TABLE subscption_order ( +if not exists (select * from sysobjects where name='subscption_orders') + CREATE TABLE subscption_orders ( subscription_order_id int not null, running_subscription bit, subscription_order_date date not null, @@ -73,17 +75,18 @@ if not exists (select * from sysobjects where name='persons') firstname varchar(50) not null, lastname varchar(50) not null, date_of_birth date not null, - email_adress varchar(50) not null, + email_address varchar(50) not null, streetname varchar(50) not null, streetnumber int, city_id int not null, country_id int not null, - constraint person_pk primary key (person_id) + constraint person_pk primary key (person_id), + constraint constraint_email_address unique (email_address) ); use marketdb; -if not exists (select * from sysobjects where name='trial_period') - CREATE TABLE trial_period ( +if not exists (select * from sysobjects where name='trial_periods') + CREATE TABLE trial_periods ( trial_period_id int not null, duration_in_seconds int not null, constraint trial_period_pk primary key (trial_period_id) @@ -95,8 +98,8 @@ if not exists (select * from sysobjects where name='quality_checks') quality_check_id int not null, check_passed bit, due_date date not null, - checking_member int not null, - checked_member int not null, + checking_member_id int not null, + checked_member_id int not null, constraint quality_check_pk primary key (quality_check_id) ); @@ -148,3 +151,104 @@ if not exists (select * from sysobjects where name='rent_prices') rent_price money not null, constraint rent_price_pk primary key (rent_price_id) ); + + +-- Add constraints + +use marketdb; +IF OBJECT_ID('dbo.[fk_com_member_id]', 'F') IS NULL + ALTER TABLE commercials ADD CONSTRAINT fk_com_member_id + FOREIGN KEY (member_id) REFERENCES members (member_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_mem_status_id]', 'F') IS NULL + ALTER TABLE members ADD CONSTRAINT fk_mem_status_id + FOREIGN KEY (member_status_id) + REFERENCES member_status (member_status_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_per_salutation_id]', 'F') IS NULL + ALTER TABLE persons ADD CONSTRAINT fk_per_salutation_id + FOREIGN KEY (salutation_id) REFERENCES salutations (salutation_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_per_city_id]', 'F') IS NULL + ALTER TABLE persons ADD CONSTRAINT fk_per_city_id + FOREIGN KEY (city_id) REFERENCES cities (city_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_per_country_id]', 'F') IS NULL + ALTER TABLE persons ADD CONSTRAINT fk_per_country_id + FOREIGN KEY (country_id) REFERENCES countries (country_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_sor_subscribtion_id]', 'F') IS NULL + ALTER TABLE subscption_orders ADD CONSTRAINT fk_sor_subscribtion_id + FOREIGN KEY (subscription_id) + REFERENCES subscriptions (subscription_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_sor_member_id]', 'F') IS NULL + ALTER TABLE subscption_orders ADD CONSTRAINT fk_sor_member_id + FOREIGN KEY (member_id) REFERENCES members (member_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_sor_location_id]', 'F') IS NULL + ALTER TABLE subscption_orders ADD CONSTRAINT fk_sor_location_id + FOREIGN KEY (location_id) REFERENCES locations (location_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_mem_person_id]', 'F') IS NULL + ALTER TABLE members ADD CONSTRAINT fk_mem_person_id + FOREIGN KEY (person_id) REFERENCES persons (person_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_qch_checking_member_id]', 'F') IS NULL + ALTER TABLE quality_checks ADD CONSTRAINT fk_qch_checking_member_id + FOREIGN KEY (checking_member_id) REFERENCES members (member_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_qch_checked_member_id]', 'F') IS NULL + ALTER TABLE quality_checks ADD CONSTRAINT fk_qch_checked_member_id + FOREIGN KEY (checked_member_id) REFERENCES members (member_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_ren_member_id]', 'F') IS NULL + ALTER TABLE rents ADD CONSTRAINT fk_ren_member_id + FOREIGN KEY (member_id) REFERENCES members (member_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_ren_rent_price_id]', 'F') IS NULL + ALTER TABLE rents ADD CONSTRAINT fk_ren_rent_price_id + FOREIGN KEY (rent_price_id) REFERENCES rent_prices (rent_price_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_rpr_location_id]', 'F') IS NULL + ALTER TABLE rent_prices ADD CONSTRAINT fk_rpr_location_id + FOREIGN KEY (location_id) REFERENCES locations (location_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_loc_city_id]', 'F') IS NULL + ALTER TABLE locations ADD CONSTRAINT fk_loc_city_id + FOREIGN KEY (city_id) REFERENCES cities (city_id); +go + +use marketdb; +IF OBJECT_ID('dbo.[fk_loc_country_id]', 'F') IS NULL + ALTER TABLE locations ADD CONSTRAINT fk_loc_country_id + FOREIGN KEY (country_id) REFERENCES countries (country_id); +go