Quote:
|
Originally Posted by r937
in the relationship you describe (nice job, by the way), you would never update the emp_proj table
you would insert into it, and delete from it, but you would never update it
example: add a new employee and register him to several existing projects
1. insert employee (obtain employeeid PK value assigned, if using auto_increment)
2. insert multiple emp_proj rows, each with same employeeid values, different projectid values
|
Well, sorry I mis-spoke on the "update" word, but thats a good point. I meant update in the general sense, but yes only "inserts" and "deletes" should occur. Thats what I'm missing. When and how (what sql) do I insert into the junction table? When do I obtain the employeeid PK value? (yes I'm using auto_increment) When do I insert into the emp_proj table?
I tried this (is this stupid?):
insert into emp_proj (employeeid, projectid) values ('select employeeid from employee', 'select projectid from project');
Tried that in my MS Access play tables and it didn't like it due to key constraints.
1. Tried this since your post:
insert into emp_proj (employeeid, projectid) values (7,2);
-That works (which is progress)
2. Tried this since your post:
insert into emp_proj (employeeid, projectid) values (7,3);
-That DOESN'T work
Why? There is a projectid with the number 3 in it in the project table. Is it something to do with how I have the relationships setup? Should I not be doing a composite key in the emp_proj table? Should I have 3 keys instead 1 being a PK, and the other 2 just Numbers?
Thanks so much. You've helped me further myself this morning.