add the solution from the teacher and update the create file
This commit is contained in:
parent
069a54908d
commit
fa29cac4d4
|
@ -0,0 +1,56 @@
|
|||
-- -------------------------------------------------------
|
||||
-- Buch-Autor DB
|
||||
--
|
||||
-- Tabellen erstellen
|
||||
-- -------------------------------------------------------
|
||||
|
||||
-- Datenbank wählen
|
||||
USE [BuchAutorDB]
|
||||
GO
|
||||
|
||||
print 'Schema wird erstellt.';
|
||||
GO
|
||||
|
||||
-- Schema erstellen
|
||||
CREATE SCHEMA [buch] AUTHORIZATION [dbo]
|
||||
GO
|
||||
|
||||
print 'Tabellen werden erstellt.';
|
||||
GO
|
||||
|
||||
-- Tabellen erstellen
|
||||
CREATE TABLE buch.tblBank
|
||||
(
|
||||
BLZ char(8) CONSTRAINT pkBLZ PRIMARY KEY,
|
||||
Bank varchar(50) NOT NULL
|
||||
);
|
||||
GO
|
||||
|
||||
CREATE TABLE buch.tblAutor
|
||||
(
|
||||
ID smallint IDENTITY(1,1) CONSTRAINT pkID PRIMARY KEY,
|
||||
Vorname varchar(20) NOT NULL,
|
||||
Nachname varchar(50) NOT NULL,
|
||||
KontoNr char(10) NULL CONSTRAINT ckKontoNr CHECK (KontoNr LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
|
||||
BLZ char(8) NULL CONSTRAINT fkBLZ REFERENCES buch.tblBank(BLZ)
|
||||
);
|
||||
GO
|
||||
|
||||
CREATE TABLE buch.tblBuch
|
||||
(
|
||||
ISBN char(13) CONSTRAINT pkISBN PRIMARY KEY,
|
||||
Titel varchar (300) NOT NULL,
|
||||
Preis money CONSTRAINT dePreis DEFAULT 0
|
||||
);
|
||||
GO
|
||||
|
||||
CREATE TABLE buch.tblAutorBuch
|
||||
(
|
||||
ID smallint NOT NULL CONSTRAINT fkID
|
||||
REFERENCES buch.tblAutor(ID),
|
||||
ISBN char(13) NOT NULL CONSTRAINT fkISBN
|
||||
REFERENCES buch.tblBuch(ISBN) ON UPDATE CASCADE,
|
||||
Anteil decimal(5,2) CONSTRAINT ckAnteil CHECK (Anteil <= 100.00),
|
||||
CONSTRAINT pkIDISBN PRIMARY KEY(ID, ISBN)
|
||||
);
|
||||
GO
|
|
@ -1,9 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SqlWorkbenchSqlProject">
|
||||
<?xml version="1.0"?>
|
||||
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="BuchAutoren">
|
||||
<Items>
|
||||
<LogicalFolder Name="Connections" Type="2" />
|
||||
<LogicalFolder Name="Queries" Type="0" />
|
||||
<LogicalFolder Name="Miscellaneous" Type="3" />
|
||||
|
||||
<LogicalFolder Name="Connections" Type="2" Sorted="true">
|
||||
<Items>
|
||||
<ConnectionNode Name="(local)\SQLEXPRESS:WIN-LAPTOP\andreas">
|
||||
<Created>2017-11-24T20:36:48.4238281+01:00</Created>
|
||||
<Type>SQL</Type>
|
||||
<Server>(local)\SQLEXPRESS</Server>
|
||||
<UserName />
|
||||
<Authentication>Windows Authentication</Authentication>
|
||||
<InitialDB>ArztDB</InitialDB>
|
||||
<LoginTimeout>30</LoginTimeout>
|
||||
<ExecutionTimeout>0</ExecutionTimeout>
|
||||
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
|
||||
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
|
||||
</ConnectionNode>
|
||||
</Items>
|
||||
</LogicalFolder>
|
||||
<LogicalFolder Name="Queries" Type="0" Sorted="true">
|
||||
<Items>
|
||||
<FileNode Name="BA_CreateTables.sql">
|
||||
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local)\SQLEXPRESS:True</AssociatedConnectionMoniker>
|
||||
<AssociatedConnSrvName>(local)\SQLEXPRESS</AssociatedConnSrvName>
|
||||
<AssociatedConnUserName />
|
||||
<FullPath>BA_CreateTables.sql</FullPath>
|
||||
</FileNode>
|
||||
<FileNode Name="create_tables.sql">
|
||||
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local)\SQLEXPRESS:True</AssociatedConnectionMoniker>
|
||||
<AssociatedConnSrvName>(local)\SQLEXPRESS</AssociatedConnSrvName>
|
||||
<AssociatedConnUserName />
|
||||
<FullPath>create_tables.sql</FullPath>
|
||||
</FileNode>
|
||||
<FileNode Name="insert_data.sql">
|
||||
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local)\SQLEXPRESS:True</AssociatedConnectionMoniker>
|
||||
<AssociatedConnSrvName>(local)\SQLEXPRESS</AssociatedConnSrvName>
|
||||
<AssociatedConnUserName />
|
||||
<FullPath>insert_data.sql</FullPath>
|
||||
</FileNode>
|
||||
</Items>
|
||||
</LogicalFolder>
|
||||
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
|
||||
<Items />
|
||||
</LogicalFolder>
|
||||
</Items>
|
||||
</SqlWorkbenchSqlProject>
|
|
@ -1,4 +1,10 @@
|
|||
CREATE DATABASE buch;
|
||||
-- CREATE DATABASE BuchAutorDB;
|
||||
|
||||
USE [BuchAutorDB]
|
||||
GO
|
||||
-- Schema erstellen
|
||||
CREATE SCHEMA [buch] AUTHORIZATION [dbo]
|
||||
GO
|
||||
|
||||
CREATE TABLE buch.tblBank
|
||||
(
|
||||
|
|
Reference in New Issue