Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 tables artist and employee as
artist(artistId,name,contact,address,employeeId) and
employee(employeeId,name,contact,email)
here artistId and employeeId are primary key and set to auto increment.
I want to insert data into artist table but artist can not insert employee Id.So how it will get assigned to artist? what should I write?
i have written following query in stored procedure without employee id:
insert into artist(name,contact,address)values(name,contact,address).

Please help.
Posted

You have to insert new employee id into the employee table first before it can be used in the artist table.
 
Share this answer
 
Comments
Member 10724668 19-Apr-14 0:09am    
yes.It is already inserted in employee table.There are many ids.
but how one of them will get assigned to artist?
Peter Leow 19-Apr-14 0:55am    
Lset say you have a new artist assigned to an employee whose employeeid is 3.
This employee id of 3 must exist as a record in the employee table first, before you can insert this new artist with the employeeid of 3 in the artist table.
If this employee id of 3 has not existed in the employee table, then you have to insert it into the employee table first, before inserting the new artist into the artist table with this employee id of 3.
You can google for more info on this topic called referential integrity relational database.
Bh@gyesh 19-Apr-14 0:38am    
Hi,
You mean to say when an entry inserted in employee table, one entry must be inserted with Artist table with newly inserted employeeid is it?
Look into http://technet.microsoft.com/en-us/library/ms190315.aspx[^]

But I recommend not using an identity / auto increment. SQL Server 2012 supports sequences, which are all kinds of better.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900