I'm experiencing my first mysql INSERT tests and I'm using these tables:
table employees
-> employee_id
-> employee_name
-> employee_surname
-> employee_url
table areas
-> area_id
-> area_city
-> area_address
-> area_country
table agencies
-> agency_id
-> agency_name
-> agency_url
table node_employees
-> node_id
-> employee_id
-> area_id
-> agency_id
I would store data in table_employee, table_areas and table_agency but I'm not forced to save all the data simultaneously, so I could create an employee, and subsequently an agency or an address.
In a case of singular data insert, should I use something like this or shoud I use directly the table node_employees, if yes, how can I do it?
INSERT INTO employees (employee_name, employee_surname, employee_url)
VALUES ('Roger', 'Waters', 'http://pinkfloyd.com')
INSERT INTO agencies (agency_name, agency_url)
VALUES ('Google', 'http://google.com')
INSERT INTO areas (area_city, area_address, area_country)
VALUES ('Rome', 'Via Roma, 123', 'Italy')
To link rows each other I've created node_employees, a relational table. I use it to link an employee with an area or an agency, so what I should do to link data with this relational table?
SELECT employee_id FROM employees WHERE employee_name = 'Roger'
SELECT agency_id FROM agencies WHERE agency_name = 'Google'
// I'll get their ids in php
$php_employee_id
$php_agency_id
// and then
INSERT INTO node_employees (employee_id, agency_id)
VALUES ('$php_employee_id', '$php_agency_id')
I have also another doubt, what I should do if I need to link an employee with an area? shoud I use a different query, so a query for every possibility?
// so, not this
$php_employee_id = 12;
$php_agency_id = 7;
$php_area_id = null;
INSERT INTO node_employees (employee_id, agency_id, area_id)
VALUES ('$php_employee_id', '$php_agency_id', '$php_area_id') // will this remove the previous data with null in area_id?