From 456129e2c804e6b9b78549fa3603995e1081ac1d Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 27 May 2017 18:12:24 +0200 Subject: [PATCH] add files for is-a excercise --- .../is_an_aircraft/is_an_aircraft.ssmssln | 18 ++++++ .../is_an_aircraft/create_database.sql | 10 ++++ .../is_an_aircraft/create_table.sql | 58 +++++++++++++++++++ .../is_an_aircraft/insert_data.sql | 21 +++++++ .../is_an_aircraft/is_an_aircraft.ssmssqlproj | 33 +++++++++++ .../is_an_aircraft/remove_database.sql | 23 ++++++++ 6 files changed, 163 insertions(+) create mode 100644 db/3_sem/is_an_aircraft/is_an_aircraft.ssmssln create mode 100644 db/3_sem/is_an_aircraft/is_an_aircraft/create_database.sql create mode 100644 db/3_sem/is_an_aircraft/is_an_aircraft/create_table.sql create mode 100644 db/3_sem/is_an_aircraft/is_an_aircraft/insert_data.sql create mode 100644 db/3_sem/is_an_aircraft/is_an_aircraft/is_an_aircraft.ssmssqlproj create mode 100644 db/3_sem/is_an_aircraft/is_an_aircraft/remove_database.sql diff --git a/db/3_sem/is_an_aircraft/is_an_aircraft.ssmssln b/db/3_sem/is_an_aircraft/is_an_aircraft.ssmssln new file mode 100644 index 0000000..0ee6f9f --- /dev/null +++ b/db/3_sem/is_an_aircraft/is_an_aircraft.ssmssln @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# SQL Server Management Studio Solution File, Format Version 13.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "is_an_aircraft", "is_an_aircraft\is_an_aircraft.ssmssqlproj", "{F39278EA-3B78-45EE-90A4-FB370F21FF41}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Default|Default = Default|Default + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F39278EA-3B78-45EE-90A4-FB370F21FF41}.Default|Default.ActiveCfg = Default + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/db/3_sem/is_an_aircraft/is_an_aircraft/create_database.sql b/db/3_sem/is_an_aircraft/is_an_aircraft/create_database.sql new file mode 100644 index 0000000..158d03e --- /dev/null +++ b/db/3_sem/is_an_aircraft/is_an_aircraft/create_database.sql @@ -0,0 +1,10 @@ +-- Dateiname create_database.sql +-- +-- Beschreibung: Is an Airplane Übung +-- +-- Autor: Andreas Zweili +-- Datum: 2017-05-27 +-- Server Version: SQL Server 2016 + +if not exists (select * from sys.databases where name='Luftfahrzeuge') + CREATE DATABASE Luftfahrzeuge; diff --git a/db/3_sem/is_an_aircraft/is_an_aircraft/create_table.sql b/db/3_sem/is_an_aircraft/is_an_aircraft/create_table.sql new file mode 100644 index 0000000..ce3bb4d --- /dev/null +++ b/db/3_sem/is_an_aircraft/is_an_aircraft/create_table.sql @@ -0,0 +1,58 @@ +-- Dateiname create_table.sql +-- +-- Beschreibung: Is an Airplane Übung +-- +-- Autor: Andreas Zweili +-- Datum: 2017-05-27 +-- Server Version: SQL Server 2016 + +use Luftfahrzeuge +if not exists (select * from sysobjects where name='Luftfahrzeug') + CREATE TABLE Luftfahrzeug ( + LFZ_ID int not null, + LFZ_HERSTELLER varchar(40) not null, + LFZ_BAUJAHR integer not null, + constraint PK_LFZ_ID primary key (LFZ_ID) + ); + +use Luftfahrzeuge +if not exists (select * from sysobjects where name='Flugzeug') + CREATE TABLE Flugzeug ( + FLZ_ID int not null, + FLU_SPANNWEITE float, + constraint PK_FLZ_ID primary key (FLZ_ID) + ); + +use Luftfahrzeuge +if not exists (select * from sysobjects where name='Hubschrauber') + CREATE TABLE Hubschrauber ( + HUB_ID int not null, + HUB_ROTORDURCHMESSER float, + constraint PK_HUB_ID primary key (HUB_ID) + ); + +use Luftfahrzeuge +if not exists (select * from sysobjects where name='Zeppelin') + CREATE TABLE Zeppelin ( + ZEP_ID int not null, + ZEP_GASVOLUMEN float, + constraint PK_ZEP_ID primary key (ZEP_ID) + ); + +-- Foreign Key Constraints hinzufügen +IF OBJECT_ID('dbo.[FK_LFZ_ID]', 'F') IS NULL + ALTER TABLE Flugzeug ADD CONSTRAINT FK_LFZ_ID + FOREIGN KEY (FLZ_ID) REFERENCES Luftfahrzeug (LFZ_ID); +go + +-- Foreign Key Constraints hinzufügen +IF OBJECT_ID('dbo.[FK_LFZ_ID]', 'F') IS NULL + ALTER TABLE Hubschrauber ADD CONSTRAINT FK_HUB_ID + FOREIGN KEY (HUB_ID) REFERENCES Luftfahrzeug (LFZ_ID); +go + +-- Foreign Key Constraints hinzufügen +IF OBJECT_ID('dbo.[FK_LFZ_ID]', 'F') IS NULL + ALTER TABLE Zeppelin ADD CONSTRAINT FK_ZEP_ID + FOREIGN KEY (ZEP_ID) REFERENCES Luftfahrzeug (LFZ_ID); +go diff --git a/db/3_sem/is_an_aircraft/is_an_aircraft/insert_data.sql b/db/3_sem/is_an_aircraft/is_an_aircraft/insert_data.sql new file mode 100644 index 0000000..f82979c --- /dev/null +++ b/db/3_sem/is_an_aircraft/is_an_aircraft/insert_data.sql @@ -0,0 +1,21 @@ +-- Dateiname insert_data.sql +-- +-- Beschreibung: Is an Airplane Übung +-- +-- Autor: Andreas Zweili +-- Datum: 2017-05-27 +-- Server Version: SQL Server 2016 + + +use Luftfahrzeuge + +insert into dbo.Luftfahrzeug (LFZ_ID, LFZ_HERSTELLER, LFZ_BAUJAHR) + values ('1000','Airbus','2012'), + ('2000','Alouette','1980'); + +insert into dbo.Flugzeug (FLZ_ID, FLU_SPANNWEITE) + values ('1000','40'); + + +insert into dbo.Hubschrauber (HUB_ID, HUB_ROTORDURCHMESSER) + values ('2000','8'); diff --git a/db/3_sem/is_an_aircraft/is_an_aircraft/is_an_aircraft.ssmssqlproj b/db/3_sem/is_an_aircraft/is_an_aircraft/is_an_aircraft.ssmssqlproj new file mode 100644 index 0000000..8f2791a --- /dev/null +++ b/db/3_sem/is_an_aircraft/is_an_aircraft/is_an_aircraft.ssmssqlproj @@ -0,0 +1,33 @@ + + + + + + + + + + + + + create_table.sql + + + + + + insert_data.sql + + + + + + remove_database.sql + + + + + + + + \ No newline at end of file diff --git a/db/3_sem/is_an_aircraft/is_an_aircraft/remove_database.sql b/db/3_sem/is_an_aircraft/is_an_aircraft/remove_database.sql new file mode 100644 index 0000000..49e9fca --- /dev/null +++ b/db/3_sem/is_an_aircraft/is_an_aircraft/remove_database.sql @@ -0,0 +1,23 @@ +-- Removes the tables for the Flugzeug DB +-- +-- Author: Andreas Zweili +-- Erstellt: 2017-05-27 +-- DB-Server SQL Server 2016 + +use Luftfahrzeuge; + +if exists (select * from sysobjects where name='Flugzeug') + drop table Flugzeug; + +if exists (select * from sysobjects where name='Hubschrauber') + drop table Hubschrauber; + +if exists (select * from sysobjects where name='Zeppelin') + drop table Zeppelin; + +if exists (select * from sysobjects where name='Luftfahrzeug') + drop table Luftfahrzeug; + +use master; +if exists (select * from sys.databases where name='Luftfahrzeuge') + drop DATABASE Luftfahrzeuge;