Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MySql Foreign key referencing

MySql Foreign key referencing

Scheduled Pinned Locked Moved Database
databasemysqlsql-serversysadminquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sajid salim khan
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • S sajid salim khan

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Do not create duplicate posts, you can edit your previous post and make your additions.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups