无法添加或更新子行:外键约束失败

时间:2014-06-06 14:53:29

标签: sql database

CREATE TABLE Student_Acedamic_History(
    S_id INT,
    Degree_Title VARCHAR(30),
    Institue VARCHAR(30),
    Year_Of_Comp INT,
    Total_Marks INT,
    Obtained_Marks INT,
    PercentAge FLOAT,
    CONSTRAINT fk_S_id_students FOREIGN KEY students(S_id)REFERENCES students (S_id)ON UPDATE CASCADE ON DELETE CASCADE
);

INSERT INTO student_acedamic_history VALUES 
(1,'FSC','GBHS',2013,1100,900,81.81),(2,'FA','PAF',2012,1100,850,77.28),(3,'ICS','APS',2011,1100,800,73),(4,'I_COM','GC',2010,1100,750,68.18),(5,'MATRIC','FC',2009,1050,800,76.2),
(6,'FSC','GBHS',2013,1100,900,81.81),(7,'FA','PAF',2012,1100,850,77.28),(8,'ICS','APS',2011,1100,800,73),(9,'I_COM','GC',2010,1100,750,68.18),(10,'MATRIC','FC',2009,1050,800,76.2),
(11,'FSC','GBHS',2013,1100,900,81.81),(12,'FA','PAF',2012,1100,850,77.28),(13,'ICS','APS',2011,1100,800,73),(14,'I_COM','GC',2010,1100,750,68.18),(15,'MATRIC','FC',2009,1050,800,76.2),
(16,'FSC','GBHS',2013,1100,900,81.81),(17,'FA','PAF',2012,1100,850,77.28),(18,'ICS','APS',2011,1100,800,73),(19,'I_COM','GC',2010,1100,750,68.18),(20,'MATRIC','FC',2009,1050,800,76.2),
(21,'FSC','GBHS',2013,1100,900,81.81),(22,'FA','PAF',2012,1100,850,77.28),(23,'ICS','APS',2011,1100,800,73),(24,'I_COM','GC',2010,1100,750,68.18),(25,'MATRIC','FC',2009,1050,800,76.2),
(26,'FSC','GBHS',2013,1100,900,81.81),(27,'FA','PAF',2012,1100,850,77.28),(28,'ICS','APS',2011,1100,800,73),(29,'I_COM','GC',2010,1100,750,68.18),(30,'MATRIC','FC',2009,1050,800,76.2),
(31,'FSC','GBHS',2013,1100,900,81.81),(32,'FA','PAF',2012,1100,850,77.28),(33,'ICS','APS',2011,1100,800,73),(34,'I_COM','GC',2010,1100,750,68.18),(35,'MATRIC','FC',2009,1050,800,76.2),
(36,'FSC','GBHS',2013,1100,900,81.81),(37,'FA','PAF',2012,1100,850,77.28),(38,'ICS','APS',2011,1100,800,73),(39,'I_COM','GC',2010,1100,750,68.18),(40,'MATRIC','FC',2009,1050,800,76.2),
(41,'FSC','GBHS',2013,1100,900,81.81),(42,'FA','PAF',2012,1100,850,77.28),(43,'ICS','APS',2011,1100,800,73),(44,'I_COM','GC',2010,1100,750,68.18),(45,'MATRIC','FC',2009,1050,800,76.2),
(46,'FSC','GBHS',2013,1100,900,81.81),(47,'FA','PAF',2012,1100,850,77.28),(48,'ICS','APS',2011,1100,800,73),(49,'I_COM','GC',2010,1100,750,68.18),(50,'MATRIC','FC',2009,1050,800,76.2);

1 个答案:

答案 0 :(得分:0)

CONSTRAINT fk_S_id_students FOREIGN KEY students(S_id) 

看起来很破碎。你没有提到你的RDBMS,但我想这应该是

CONSTRAINT fk_S_id_students FOREIGN KEY Student_Acedamic_History(S_id)

或只是

CONSTRAINT fk_S_id_students FOREIGN KEY S_id