Jump to content

dweeb

New Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by dweeb

  1. Hi 

     

    I need some help with the idea of foreign keys please and how they work when inserting data.

     

    I have two tables

     

    CLIENTS

    client_id   PK AUTOINCREMENT

    client_name

    address_id

     

    ADDRESS

    address_id  PK AUTOINCREMENT

    building_name

    street_name

    town

     

    I want to relate the two via the address_id which I  think I have to make a foreign key in the clients table but am unsure of how to do this. I believe that this will also mean I cannot add a client without a related address. Is this correct? how do I make the address_id in the clients table a foreign key? I am using phpmyadmin via cpanel on my hosting account, do i need to declare it like a primary key?

     

    Also when I add a new client with address at the same time via an insert statement how would i get the new address_id to insert into the clients table or would this happen automatically?

     

    Thanks

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.