试图在这里的电视节目中为球队建立数据库。
但是当我尝试将数据插入tblShowteam
出现以下错误。
Msg 2627, Level 14, State 1, Line 2
Violation of PRIMARY KEY constraint 'PK__tblShowt__F693078C03317E3D'. Cannot insert duplicate key in object 'dbo.tblShowteam'.
桌子
-- tabbellen aanmaken
create table tblShow(
setId int,
Datum date,
teams int
primary key (setId));
create table tblShowteam(
SetId int,
datum date,
teams int,
primary key (teams));
create table tblTeam(
TeamId int,
Coach varchar(35),
CoachId int,
teams int
primary key (CoachId));
-- participant table
create table tblDeelnemer(
DeelnemerId int identity(1, 1),
DeelnemerV varchar(35),
deelnemerT_V varchar(10),
DeelnemerA varchar(35),
CoachId int,
datum_optreden date
primary key (DeelnemerId));
--table for the public viewers
create table tblKijker(
Kijkerv varchar(35),
KijkerT_V varchar(10),
KijkerA varchar(35),
Stoelnummer int identity(1,3),
ShowId int Not null,
Email varchar(35)
primary key (Email));
我的插入内容如下所示:
insert into tblShowteam values (1, '2014-06-28', 1)
insert into tblShowteam values (2, '2014-06-05', 1)
insert into tblShowteam values (3, '2014-06-12', 1)
insert into tblShowteam values (4, '2014-06-19', 1)
insert into tblShowteam values (5, '2014-06-26', 1)
所有其他插入(在不同的表中)的工作方式都正常。
我在这里做错了什么?
最佳答案
你的问题在这里
primary key (teams));
我想你必须那样做
primary key (setId));
像那样:
create table tblShowteam(
SetId int,
datum date,
teams int,
primary key (setId));
因为您在将团队用作
1
时插入相同的团队primary key
,这意味着没有重复项。关于mysql - 消息2627违反主键约束,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24351262/