Referencja w bazie danych

0

Witam tworze na ćwiczenia swoją baze danych o tematyce NBA mam niestety małe problemy z tworzeniem referencji ( jestem totalnym laikiem). Podczas kompilacji INSERT-ów wyskakują błędy
**
Msg 2627, Level 14, State 1, Line 63
Violation of PRIMARY KEY constraint 'PK__Matches__4218C8378B48124E'. Cannot insert duplicate key in object 'dbo.Matches'. The duplicate key value is (1).
The statement has been terminated.**

Msg 547, Level 16, State 0, Line 69
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__GameStati__Playe__440B1D61". The conflict occurred in database "LigaNBA", table "dbo.Players", column 'PlayerID'.
The statement has been terminated.

Kod jest podany poniżej, nie wiem kompletnie o co chodzi poniewaz jak wspominałem jestem zielony w temacie także byłbym wdzięczny za jakiekolwiek naprowadzenie bądź wskazówki


CREATE DATABASE LigaNBA;
USE LigaNBA;
GO

Create Table Conferences
(
	Division varchar(50) PRIMARY KEY , 
	Conference varchar (50),
	
)

Create Table Objekt
(
	Arena varchar(30) PRIMARY KEY , 
	City varchar(30)
)
Create Table Clubs
(
	Division varchar(50) REFERENCES Conferences(Division), 
	Team varchar(30) PRIMARY KEY  ,
	CreationTime Date, 
	TeamColors varchar(50), 
	Arena varchar (30) REFERENCES Objekt(Arena),

	
)
Create Table Matches
(
	 MatchID int PRIMARY KEY,
	 MatchDate Date, 
	 Winner varchar(30), 
	 Loser varchar(30), 
	 Home varchar(30), 
	 Away varchar(30), 
	 HomePts int, 
	 AwayPts int,
)
Create Table Players
(
	PlayerID int PRIMARY KEY, 
	Surname varchar(30), 
	Name varchar(30), 
	Position varchar(15), 
	Team varchar(30) REFERENCES Clubs(Team), 
	BirthDate date, 
	HireDate date,
	
)

Create Table GameStatistic
(
	MatchID int REFERENCES Matches(MatchID),
	Team varchar(30),
	PlayerID int REFERENCES Players(PlayerID),
	Points int, 
	Rebounds int, 
	Blocks int, 
	Turnovers int, 
	Steal int

)

INSERT INTO Matches
(MatchID, MatchDate, Winner, Loser, Home, Away, HomePts, AwayPts)
Values
(1, '2018-05-15', 'Minnesota', 'Chicago Bulls', 'Chicago Bulls', ' Minnesota', 120, 121),
(2, '2018-05-15', 'LA Lakers', 'Miami Heat', 'La Lakers', 'Miami Heat', 134, 118)

Insert INTO GameStatistic
(MatchID, Team, PlayerID, Points, Rebounds, Blocks, Turnovers, Steal)
Values
(1, 'Minnesota', 12, 34, 2, 4, 0, 8),
(2, 'Miami', 1, 9, 0, 1, 5, 0),
(3, 'Minnesota', 10, 34, 11, 4, 17, 8)

Select *
FROM GameStatistic
0

Podany przez Ciebie kod - po poprawieniu literówek - działa prawidłowo.
Btw, to jest klucz obcy, nie referencja.

0

Masz napisane. Nie wiem czego nie rozumiesz? Zrób selecta na obu tych tabelach i zobaczysz że już masz te dane w tabelce.

1 użytkowników online, w tym zalogowanych: 0, gości: 1