My problem arises when I want to link two existing tables.
I am very new to the field and have only been dealing with databases for a few days.
It would be great if someone could help me and tell me what I did wrong.
I use "microsoft / mssql-server-linux: latest" in a Docker and "Azure Data Studio" as editor.
CREATE TABLE Bestellung
(
BestlNr INTEGER NOT NULL,
Datum INTEGER,
Gesamtpreis INTEGER,
PRIMARY KEY (BestlNr)
) ;
CREATE TABLE Kunde
(
KdNr INTEGER NOT NULL,
Vorname VARCHAR,
Nachnahme VARCHAR,
Geburtsdatum INTEGER,
Strasse VARCHAR,
Hausnummer VARCHAR,
Ort VARCHAR,
PLZ INTEGER,
Passwort VARCHAR(50),
PRIMARY KEY (KdNr),
) ;
ALTER TABLE Bestellung
ADD CONSTRAINT Bestellung, FOREIGN KEY (KdNr),
REFERENCES Kunde (KdNr),
ON DELETE CASCADE
ON UPDATE CASCADE;
first of all you need to add a column for your Foreign key in Bestellung table
so:
then make the relationship