开发者

foreign key problem - mysql

i have this mysql code, but when i delete an element of agrupamento, the child is not deleted in emprego, and it is supposed.

For example i have in agrupamento - id - 1 || area - science

and i have in profissao (job) - ref - 1 || empregoid - 1 || emprego - scientist

 CREATE TABLE agrupamento (  
        id smallint(5) unsigned NOT NULL auto_in开发者_运维技巧crement,  
        area varchar(30),  
        PRIMARY KEY (id) 
    )

CREATE TABLE emprego (  
    ref int(10) unsigned NOT NULL auto_increment,  
    empregoid smallint(5) unsigned NOT NULL,  
    emprego varchar(50),  
    PRIMARY KEY (ref)  
)

    ALTER TABLE emprego  
    ADD CONSTRAINT FK_emprego
    FOREIGN KEY (empregoid) REFERENCES agrupamento(id)  
    ON UPDATE CASCADE  
    ON DELETE CASCADE;  

what is the problem?

(if the area science doesn't exists, the scientist also not.)

thanks!


What is the kind of table that are you using in your database, certify that the table is innoDB to use FK. In myIsam tables it will not work properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜