我在嘗試在數據庫中插入一些數據時出現此錯誤。INSERT語句與FOREIGN KEY約束衝突。錯誤消息與我的sql語句
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','[email protected]','[email protected]','Philippines','12345','0277824893'),
('Dev123456B','Actor One','@ctor1','[email protected]','New Zealand','11234','0293847567'),
('Dev123456C','Actor Two','@ctor2','[email protected]','USA','42562','028394576'),
('Dev123456D','Actor Three','@ctor3','[email protected]','USA','93847','0294857689'),
('Dev123456E','Actor Four','@ctor4','[email protected]','Australia','02947','0293847563'),
('Dev123456F','Actor Five','@ctor5','[email protected]','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');
檢查,有沒有衝突目前,然後刪除該FK添加數據並添加FK回來。 –
這是什麼DBMS?我猜可能SQL Server給予使用dbo。可以幫助將其添加到問題中。 –
我在小提琴中嘗試過你的唱片,它的工作完美。 http://www.sqlfiddle.com/#!3/4c27e/1 –