From 370af5e89ba3fe05858c03bd198bf52fac5e2d78 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 24 Jun 2017 15:32:42 +0200 Subject: [PATCH] first draft of the create table script --- sql/sql/setup_02_create_table.sql | 141 +++++++++++++++++++++++++++ sql/sql/setup_04_remove_database.sql | 77 +++++++++++++++ 2 files changed, 218 insertions(+) diff --git a/sql/sql/setup_02_create_table.sql b/sql/sql/setup_02_create_table.sql index 7c8caae..d09c521 100644 --- a/sql/sql/setup_02_create_table.sql +++ b/sql/sql/setup_02_create_table.sql @@ -7,3 +7,144 @@ -- Server Version: SQL Server 2016 use marketdb; +if not exists (select * from sysobjects where name='commercials') + CREATE TABLE commercials ( + commercial_id int not null, + date_since_last_change date not null, + member_id int not null, + constraint commercial_id primary key (commercial_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='member_status') + CREATE TABLE member_status ( + member_status_id int not null, + status_name varchar(50) not null, + constraint member_status_id primary key (member_status_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='salutation') + CREATE TABLE salutation ( + salutation_id int not null, + salutation_name varchar(50) not null, + constraint salutation_id primary key (salutation_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='subscription') + CREATE TABLE subscription ( + subscription_id int not null, + max_rented_locations int not null, + subscription_price money not null, + subscription_name varchar(50) not null, + duration_in_seconds INT, + constraint subscription_id primary key (subscription_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='subscption_order') + CREATE TABLE subscption_order ( + subscription_order_id int not null, + running_subscription bool, + subscription_order_date date not null, + subscription_id int not null, + member_id int not null, + location_id int not null, + constraint subscription_order_id primary key (subscription_order_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='members') + CREATE TABLE members ( + member_id int not null, + password varchar(50) not null, + member_status_id int not null, + date_of_registration date not null, + person_id int, + constraint member_id primary key (member_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='persons') + CREATE TABLE persons ( + person_id int not null, + salutation_id int not null, + firstname varchar(50) not null, + lastname varchar(50) not null, + date_of_birth date not null, + email_adress varchar(50) not null, + streetname varchar(50) not null, + streetnumber int, + city_id int not null, + country_id int not null, + constraint person_id primary key (person_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='trial_period') + CREATE TABLE trial_period ( + trial_period_id int not null, + duration_in_seconds int not null, + constraint trial_period_id primary key (trial_period_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='quality_checks') + CREATE TABLE quality_checks ( + quality_check_id int not null, + check_passed bool, + due_date date not null, + checking_member int not null, + checked_member int not null, + constraint quality_check_id primary key (quality_check_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='cities') + CREATE TABLE cities ( + city_id int not null, + city_name varchar(50) not null, + zip_code int not null, + constraint city_id primary key (city_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='countries') + CREATE TABLE countries ( + country_id int not null, + country_name varchar(50) not null, + constraint country_id primary key (country_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='rents') + CREATE TABLE rents ( + rent_id int not null, + rent_date date not null, + payment_date date not null, + member_id int not null, + rent_price_id int not null + constraint rent_id primary key (rent_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='locations') + CREATE TABLE locations ( + location_id int not null, + streetname varchar(50) not null, + location_capacity int not null, + location_name varchar(50) not null, + city_id int not null, + country_id int not null, + constraint location_id primary key (location_pk) + ); + +use marketdb; +if not exists (select * from sysobjects where name='rent_prices') + CREATE TABLE rent_prices ( + rent_price_id int not null, + location_id int not null, + rent_price money not null, + constraint rent_price_id primary key (rent_price_pk) + ); diff --git a/sql/sql/setup_04_remove_database.sql b/sql/sql/setup_04_remove_database.sql index 5b7c2b9..5d458c6 100644 --- a/sql/sql/setup_04_remove_database.sql +++ b/sql/sql/setup_04_remove_database.sql @@ -5,6 +5,83 @@ -- DB-Server SQL Server 2016 use marketdb; +-- Dateiname create_table.sql +-- +-- Beschreibung: Queries zum erstellen der Tabellen der Case Study DB +-- +-- Autor: Andreas Zweili +-- Datum: 2017-06-05 +-- Server Version: SQL Server 2016 + +use marketdb; +if exists (select * from sysobjects where name='commercials') + DROP TABLE commercials ( + ); + +use marketdb; +if exists (select * from sysobjects where name='member_status') + DROP TABLE member_status ( + ); + +use marketdb; +if exists (select * from sysobjects where name='salutation') + DROP TABLE salutation ( + ); + +use marketdb; +if exists (select * from sysobjects where name='subscription') + DROP TABLE subscription ( + ); + +use marketdb; +if exists (select * from sysobjects where name='subscption_order') + DROP TABLE subscption_order ( + ); + +use marketdb; +if exists (select * from sysobjects where name='members') + DROP TABLE members ( + ); + +use marketdb; +if exists (select * from sysobjects where name='persons') + DROP TABLE persons ( + ); + +use marketdb; +if exists (select * from sysobjects where name='trial_period') + DROP TABLE trial_period ( + ); + +use marketdb; +if exists (select * from sysobjects where name='quality_checks') + DROP TABLE quality_checks ( + ); + +use marketdb; +if exists (select * from sysobjects where name='cities') + DROP TABLE cities ( + ); + +use marketdb; +if exists (select * from sysobjects where name='countries') + DROP TABLE countries ( + ); + +use marketdb; +if exists (select * from sysobjects where name='rents') + DROP TABLE rents ( + ); + +use marketdb; +if exists (select * from sysobjects where name='locations') + DROP TABLE locations ( + ); + +use marketdb; +if exists (select * from sysobjects where name='rent_prices') + DROP TABLE rent_prices ( + ); use master; if exists (select * from sys.databases where name='marketdb')