-- 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 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_pk primary key (commercial_id) ); 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_pk primary key (member_status_id) ); 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_pk primary key (salutation_id) ); 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_pk primary key (subscription_id) ); use marketdb; if not exists (select * from sysobjects where name='subscption_order') CREATE TABLE subscption_order ( subscription_order_id int not null, running_subscription bit, subscription_order_date date not null, subscription_id int not null, member_id int not null, location_id int not null, constraint subscription_order_pk primary key (subscription_order_id) ); 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_pk primary key (member_id) ); 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_pk primary key (person_id) ); 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_pk primary key (trial_period_id) ); use marketdb; if not exists (select * from sysobjects where name='quality_checks') CREATE TABLE 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, constraint quality_check_pk primary key (quality_check_id) ); 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_pk primary key (city_id) ); 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_pk primary key (country_id) ); 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_pk primary key (rent_id) ); 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_pk primary key (location_id) ); 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_pk primary key (rent_price_id) );