October 29th, 2012, 07:48 PM
SQL and Foreign keys and Data Use
Can I ask a hypothetical question as I have a gap in my understanding and not sure what to review.
My Example, I have 3 tables for a meeting agenda.
Meetings letters A - J in it
Rooms the numbers 1 - 12 in it
TableAForeignKey - 1 to many
TableBForeignKey - 1 to many
Now lets say Table represents a round of meeting and Table B identifies room numbers. I want to enter in meetings.
So Insert (A, 1, tom, bill, 1pm)
iNSERT(A, 2, jerry, jane, 2pm)
and so on.
But field 1 and field 2 in the insert are the foreignkeys and the data already exists in tableA and table B. it will error if you try to insert.
How do I insert the meeting data so that it is linked up and combines the meeting, rooms times and people.
I know could change the table design but I am just trying to understand this facet of SQL in particular.
October 29th, 2012, 08:36 PM
Maybe I'm not understanding your example, but if you're inserting records with foreign keys those foreign key values are supposed to already exist in the other table before you perform the insert and you won't receive an error.
October 29th, 2012, 09:03 PM
In SQL server I receive an error cannot update base tables when doing this.
October 29th, 2012, 10:52 PM
It's just got me really confused.
October 30th, 2012, 07:31 PM
Maybe it's something specific to mssql then, I haven't work with it before so I'm not sure.
October 30th, 2012, 10:03 PM
i'm moving your thread to the microsoft sql server forum
it would help if you gave your actual table designs, not fake ones, as well as your actual error message
October 31st, 2012, 03:12 AM
I think I should be inserting with inner join. I haven't stated what the real tables as from prior experience the mere mention of 'Sport' throws people into confusion .