Compare commits
4 commits
45f76eab17
...
6c19b77768
Author | SHA1 | Date | |
---|---|---|---|
6c19b77768 | |||
cf21ead3e2 | |||
ee6bb34405 | |||
ebd05ca96c |
4 changed files with 79 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
.idea
|
.idea
|
||||||
|
db/*
|
12
db_scripts/README.md
Normal file
12
db_scripts/README.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# Datenbank
|
||||||
|
|
||||||
|
## Aufsetzen - SQLite
|
||||||
|
|
||||||
|
Erstellen / Verbinden mit der Datenbank
|
||||||
|
```sqlite3 ../db/test.db```
|
||||||
|
|
||||||
|
Tabellen anlegen (nach Verbindung durch *sqlite3* besteht)
|
||||||
|
```.read create.sql```
|
||||||
|
|
||||||
|
In einem Schritt:
|
||||||
|
```sqlite3 ../db/test.db -init create.sql```
|
62
db_scripts/create.sql
Normal file
62
db_scripts/create.sql
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS mitglied (
|
||||||
|
mitglied_id INT NOT NULL PRIMARY KEY,
|
||||||
|
haushalt VARCHAR(100) NOT NULL,
|
||||||
|
erweiterter_haushalt VARCHAR(100),
|
||||||
|
einlage INT NOT NULL,
|
||||||
|
guthaben INT NOT NULL,
|
||||||
|
kontoauszuege BOOLEAN NOT NULL,
|
||||||
|
aktiv BOOLEAN NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS transaktion_art (
|
||||||
|
art_id INT NOT NULL PRIMARY KEY,
|
||||||
|
art VARCHAR(50) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT OR IGNORE INTO transaktion_art(art_id, art) VALUES (1, 'monatlicher_beitrag');
|
||||||
|
INSERT OR IGNORE INTO transaktion_art(art_id, art) VALUES (2, 'aufladung');
|
||||||
|
INSERT OR IGNORE INTO transaktion_art(art_id, art) VALUES (3, 'einkauf');
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS transaktion (
|
||||||
|
transaktion_id INT NOT NULL PRIMARY KEY,
|
||||||
|
mitglied_id INT NOT NULL,
|
||||||
|
art_id INT NOT NULL,
|
||||||
|
datum DATE NOT NULL,
|
||||||
|
BETRAG INT NOT NULL,
|
||||||
|
CONSTRAINT fk_mitglied_transaktion FOREIGN KEY (mitglied_id) REFERENCES mitglied(mitglied_id),
|
||||||
|
CONSTRAINT fk_art_transaktion FOREIGN KEY (art_id) REFERENCES transaktion_art(art_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS monatlicher_beitrag (
|
||||||
|
monatlicher_beitrag_id INT NOT NULL PRIMARY KEY,
|
||||||
|
mitglied_id INT NOT NULL,
|
||||||
|
anfangsdatum DATE NOT NULL,
|
||||||
|
enddatum DATE NOT NULL,
|
||||||
|
beitrag INT NOT NULL,
|
||||||
|
CONSTRAINT fk_mitglied_beitrag FOREIGN KEY (mitglied_id) REFERENCES mitglied(mitglied_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS mwst (
|
||||||
|
mwst_id INT NOT NULL PRIMARY KEY,
|
||||||
|
prozent INT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT OR IGNORE INTO mwst(mwst_id, prozent) VALUES (1, 7);
|
||||||
|
INSERT OR IGNORE INTO mwst(mwst_id, prozent) VALUES (2, 19);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS einheit(
|
||||||
|
einheit_id INT NOT NULL PRIMARY KEY,
|
||||||
|
bezeichnung VARCHAR(50) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT OR IGNORE INTO einheit(einheit_id, bezeichnung) VALUES (1, 'stueck');
|
||||||
|
INSERT OR IGNORE INTO einheit(einheit_id, bezeichnung) VALUES (2, 'menge');
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS artikel (
|
||||||
|
artikel_id INT NOT NULL PRIMARY KEY,
|
||||||
|
einheit_id INT NOT NULL,
|
||||||
|
mwst_id INT NOT NULL,
|
||||||
|
preis INT NOT NULL,
|
||||||
|
CONSTRAINT fk_mwst_artikel FOREIGN KEY (mwst_id) REFERENCES mwst(mwst_id),
|
||||||
|
CONSTRAINT fk_einheit_artikel FOREIGN KEY (einheit_id) REFERENCES einheit(einheit_id)
|
||||||
|
);
|
3
db_scripts/create_server.sql
Normal file
3
db_scripts/create_server.sql
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
CREATE SERVER IF NOT EXISTS s
|
||||||
|
FOREIGN DATA WRAPPER mysql
|
||||||
|
OPTIONS (USER 'REMOTE', HOST '127.0.0.1', DATABASE 'test');
|
Loading…
Reference in a new issue