MySQL Foreign Key Referencing

后端 未结 1 1119
盖世英雄少女心
盖世英雄少女心 2021-01-26 21:29

I m a new bee i have used sql server 2000 before my question is when creating two tables in sql server 2000 say location and projects table projects having a foreign key referen

相关标签:
1条回答
  • 2021-01-26 21:42

    From what I can see in the example, you haven't inserted anything in the projects table in which to have a cascaded update or delete performed.

    I would suggest as a better example to demonstrate the behaviour you're after that you perform the following, after doing the steps above:

    insert into projects values (1,1);
    select * from projects;
    update location set id = 2 where id = 1;
    select * from projects;
    

    What you should end up seeing, is that initially the location_id in the inserted projects row will be equal to 1, then after the update of location, the location_id in projects should change to 2. This demonstrates that the change to the id of the location table has cascaded to update the location_id field of the row in the projects table.

    0 讨论(0)
提交回复
热议问题