尝试在我的数据库中插入一些数据时出现此错误。
INSERT 语句与 FOREIGN KEY 约束冲突
FK_DevID_Prog
。ElectricImp
数据库、表dbo.Developer
、列发生冲突DevID
。
代码:
Create Table Developer
(
DevID Char(10) Not Null,
UserName Char(20) Not Null,
DevPassword Char(20) Not Null,
Email VarChar(20) Not Null,
Country VarChar(25) Not Null,
ZipCode Integer,
CellPhone Integer Not Null,
Constraint PK_DevID Primary Key(DevID)
);
--Drop Table Programme;
Create Table Programme
(
ProgrammeID Char(10) Not Null,
DevID Char(10) Not Null,
ProgrammeName VarChar(20) Not Null,
ProgrammeCode VarChar(20) Not Null,
Constraint PK_ProgID Primary Key(ProgrammeID),
Constraint FK_DevID_Prog Foreign Key(DevID) References Developer(DevID)
Insert Into
Developer(DevID,UserName,DevPassword,Email,Country,ZipCode,CellPhone)
Values
('Dev123456A','Paul Wilson Diu','P@ulWilson','Paul_Wilson@yahoo.com','Philippines','12345','0277824893'),
('Dev123456B','Actor One','@ctor1','Actor_One@yahoo.com','New Zealand','11234','0293847567'),
('Dev123456C','Actor Two','@ctor2','Actor_Two@yahoo.com','USA','42562','028394576'),
('Dev123456D','Actor Three','@ctor3','Actor_Three@yahoo.com','USA','93847','0294857689'),
('Dev123456E','Actor Four','@ctor4','Actor_Four@yahoo.com','Australia','02947','0293847563'),
('Dev123456F','Actor Five','@ctor5','Actor_Five@gmail.com','Germany','92846','0293748123');
Insert Into
Programme(ProgrammeID,DevID,ProgrammeName,ProgrammeCode)
Values
('Prog12345A','Dev123456A','Programme A','ProgCode123A'),
('Prog12345B','Dev123456B','Programme B','ProgCode123B'),
('Prog12345C','Dev123456A','Programme C','ProgCode123C'),
('Prog12345D','Dev123456C','Programme D','ProgCode123D'),
('Prog12345E','Dev123456B','Programme E','ProgCode123E'),
('Prog12345F','Dev123456D','Programme F','ProgCode123F'),
('Prog12345G','Dev123456C','Programme G','ProgCode123G'),
('Prog12345H','Dev123456E','Programme H','ProgCode123H');