I have an issue with a SQL query
I have a table which has two columns, employee_name
, phone_number
. This table has 100 rows.
I want to store employee_name
in one table and phone_number
in another table and have a relationship. I will explain the schema
EmployeeTable
emp_id (identity)
emp_name (text)
ph_id (FK from the phone table)
phone table
ph_id (identity)
phone_number
So I tried
insert into emp_table (emp_name, ph_id)
select employee_name, (insert into phone_table output inserted.ph_id values (whole.phone)) as phone_id
this query is wrong. But this is what I am trying to do.
I want to insert phone number into phone number table and have the identity in the same select statement and insert into the employee table.
Your thoughts?
The final table should be
Whole table (This is what I have now)
emp_name phone_number
----------------------
name1 123
name2 456
name4 789
and after query executed
employee_table
name ph_id
-------------
name1 1
name2 2
name3 3
phone_table
phone_id phone_number
-------------------------
1 123
2 456
3 789