PMG2426 1/DB Beleg/Emma
Aus ProgrammingWiki
Wiki-Quelltext dieser Seite.
<language>SQL</language>
='''Datenbankprojekt: Tattoostudio'''=
''➥Was ist im Trend?''
====Ziel der Datenbank====
----
Die Datenbank soll zeigen, welche Artists und Tattoo-Motive am beliebtesten sind. Dadurch kann man für die Zukunft besser planen, hinsichtlich Marketing und Künstler-Einsatz.
====Modellierung in einem ERM====
----
[[Bild:EmmErdplus.png | 750px ]]
====Transformation in das Relationenmodell====
----
KUNDE (''' Kunde_Nr''', Name_Kun, Geburtsdatum)
ARTIST (''' Artist_Nr''', Name_Art, Erfahrung_Jahre)
MOTIV (''' Motiv_Nr''', Motivname, Kategorie)
TATTOO (''' Tattoo_Nr''', Datum, Preis, Körperstelle, ''Kunde_Nr, Artist_Nr, Motiv_Nr'')
====Erstellte Datenbank====
----
<code id="6979ca1e6c24a">
DROP TABLE IF EXISTS Kunde;
CREATE TABLE Kunde (
Kunde_Nr VARCHAR NOT NULL UNIQUE,
Name_Kun VARCHAR(50),
Geburtsdatum DATE,
PRIMARY KEY (Kunde_Nr)
);
DROP TABLE IF EXISTS Artist;
CREATE TABLE Artist (
Artist_Nr VARCHAR NOT NULL UNIQUE,
Name_Art VARCHAR(50),
Erfahrung_Jahre INT,
PRIMARY KEY (Artist_Nr)
);
DROP TABLE IF EXISTS Motiv;
CREATE TABLE Motiv (
Motiv_Nr VARCHAR NOT NULL UNIQUE,
Motivname VARCHAR(50),
Kategorie VARCHAR(30),
PRIMARY KEY (Motiv_Nr)
);
DROP TABLE IF EXISTS Tattoo;
CREATE TABLE Tattoo (
Tattoo_Nr VARCHAR NOT NULL UNIQUE,
Datum DATE,
PREIS DECIMAL (6,2),
Koerperstelle VARCHAR(30),
Kunde_Nr VARCHAR,
Artist_Nr VARCHAR,
Motiv_Nr VARCHAR,
PRIMARY KEY (Tattoo_Nr),
FOREIGN KEY (Kunde_Nr) REFERENCES Kunde(Kunde_Nr),
FOREIGN KEY (Artist_Nr) REFERENCES Artist(Artist_Nr),
FOREIGN KEY (Motiv_Nr) REFERENCES Motiv(Motiv_Nr)
);
INSERT INTO Kunde VALUES ('1', 'Lisa Müller', '2003-05-12');
INSERT INTO Kunde VALUES ('2', 'Marielle Pupshaus', '2005-04-08');
INSERT INTO Kunde VALUES ('3', 'Luis Pfeiffer', '2001-09-25');
INSERT INTO Kunde VALUES ('4', 'Lisa Müller', '1967-11-29');
INSERT INTO Artist VALUES ('1', 'Max', 8);
INSERT INTO Artist VALUES ('2', 'Sarah', 6);
INSERT INTO Artist VALUES ('3', 'Unicorn', 7);
INSERT INTO Motiv VALUES ('1', 'Rose', 'Blume');
INSERT INTO Motiv VALUES ('2', 'Löwe', 'Tier');
INSERT INTO Motiv VALUES ('3', 'Dynamo Dresden', 'Vereinslogo');
INSERT INTO Tattoo VALUES ('1', '2025-01-10', 180.00, 'Unterarm', '1','1','1');
INSERT INTO Tattoo VALUES ('2', '2026-01-15', 240.00, 'Bein', '2','3','3');
INSERT INTO Tattoo VALUES ('3', '2025-11-23', 348.00, 'Rücken', '3','1','2');
INSERT INTO Tattoo VALUES ('4', '2025-12-13', 120.00, 'Handgelenk', '4','2','1');
</code>
Welche Informationen gibt es über Artist Nummer 1?
<run id="69824ce50a1e5">
SELECT * FROM Artist
WHERE Artist_Nr = 1
</run>
Oben ist zusehen, welcher Artist am beliebtesten ist:
<run id="6979ca1e6c2b8">
SELECT COUNT(*) AS Anzahl, Tattoo.Artist_Nr, Name_Art
FROM Tattoo, Artist
WHERE Tattoo.Artist_Nr = '1' AND Artist.Artist_Nr = Tattoo.Artist_Nr;
SELECT COUNT(*) AS Anzahl, Tattoo.Artist_Nr, Name_Art
FROM Tattoo, Artist
WHERE Tattoo.Artist_Nr = '2' AND Artist.Artist_Nr = Tattoo.Artist_Nr;
SELECT COUNT(*) AS Anzahl, Tattoo.Artist_Nr, Name_Art
FROM Tattoo, Artist
WHERE Tattoo.Artist_Nr = '3' AND Artist.Artist_Nr = Tattoo.Artist_Nr;
</run>
Oben ist zu sehen, welches Motiv am meisten gestochen wurde:
<run id="69824c7686995">
SELECT COUNT (*) AS Anzahl, Tattoo.Motiv_Nr, Motiv. Motivname
FROM Tattoo, Motiv
WHERE Tattoo.Motiv_Nr = '1' AND Motiv.Motiv_Nr = Tattoo.Motiv_Nr;
SELECT COUNT (*) AS Anzahl, Tattoo. Motiv_Nr, Motiv. Motivname
FROM Tattoo, Motiv
WHERE Tattoo.Motiv_Nr = '2' AND Motiv. Motiv_Nr = Tattoo. Motiv_Nr;
SELECT COUNT (*) AS Anzah1, Tattoo. Motiv_Nr, Motiv. Motivname
FROM Tattoo, Motiv
WHERE Tattoo.Motiv_Nr = '3' AND Motiv.Motiv_Nr = Tattoo. Motiv_Nr;
</run>
Zu welcher Kategorie gehört das Motiv Löwe?
<run id="698306156fe42">
SELECT Kategorie FROM Motiv
WHERE Motivname = 'Löwe'
</run>
====Verschiedene Abfragen====
----
====Reflexion====
----
====Quellen====
----
https://www.w3schools.com/sql/sql_count.asp
https://erdplus.com/