MySql Foreign key referencing
-
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 referencing the location table when inserting values in location the projects is also updated thats is no need to insert the similar value in the foreign key in projects table why is it not possible in mysql when i insert values in location using insert command and when using select command on projects it does not shows the value in foreign key please check the below code mysql> create table location( -> id int not null, -> primary key(id)) -> engine=innodb; Query OK, 0 rows affected (0.11 sec) mysql> create table projects( -> id int, -> location_id int, -> foreign key(location_id) references location(id) on update cascade on del ete cascade) -> engine=innodb; Query OK, 0 rows affected (0.31 sec) mysql> insert into location values('1') Query OK, 1 row affected (0.34 sec) mysql> select * from location; +----+ | id | +----+ | 1 | +----+ 1 row in set (0.00 sec) mysql> select * from projects; Empty set (0.00 sec) as u see in the above code it was possible in sql server 2000 that the value was reflected in the child table why is it not possible in MySql Why should the value be insert in both the tables isn't it possible in MySql that when i insert in the location table the projects table pick the value automatically and show it in select Query when i query the projects table
-
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 referencing the location table when inserting values in location the projects is also updated thats is no need to insert the similar value in the foreign key in projects table why is it not possible in mysql when i insert values in location using insert command and when using select command on projects it does not shows the value in foreign key please check the below code mysql> create table location( -> id int not null, -> primary key(id)) -> engine=innodb; Query OK, 0 rows affected (0.11 sec) mysql> create table projects( -> id int, -> location_id int, -> foreign key(location_id) references location(id) on update cascade on del ete cascade) -> engine=innodb; Query OK, 0 rows affected (0.31 sec) mysql> insert into location values('1') Query OK, 1 row affected (0.34 sec) mysql> select * from location; +----+ | id | +----+ | 1 | +----+ 1 row in set (0.00 sec) mysql> select * from projects; Empty set (0.00 sec) as u see in the above code it was possible in sql server 2000 that the value was reflected in the child table why is it not possible in MySql Why should the value be insert in both the tables isn't it possible in MySql that when i insert in the location table the projects table pick the value automatically and show it in select Query when i query the projects table