The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MS SQL Development
|
SQL and Foreign keys and Data Use
Discuss SQL and Foreign keys and Data Use in the MS SQL Development forum on Dev Shed. SQL and Foreign keys and Data Use MS SQL Development forum discussing administration, MS SQL queries, and other MS SQL-related topics. SQL Server is Microsoft's enterprise database engine.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 29th, 2012, 06:48 PM
|
|
Contributing User
|
|
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68
Time spent in forums: 13 h 3 m 55 sec
Reputation Power: 8
|
|
|
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.
TableA is:
TableAPrimaryKey
Meetings
Meetings letters A - J in it
TableB is:
TableBPrimaryKey
Rooms
Rooms the numbers 1 - 12 in it
TableC is:
TableCPrimaryKey
Name1
Name2
Time
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.
Thank You
|

October 29th, 2012, 07:36 PM
|
 |
Lost in code
|
|
|
|
|
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, 08:03 PM
|
|
Contributing User
|
|
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68
Time spent in forums: 13 h 3 m 55 sec
Reputation Power: 8
|
|
|
In SQL server I receive an error cannot update base tables when doing this.
|

October 29th, 2012, 09:52 PM
|
|
Contributing User
|
|
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68
Time spent in forums: 13 h 3 m 55 sec
Reputation Power: 8
|
|
|
It's just got me really confused.
|

October 30th, 2012, 06:31 PM
|
 |
Lost in code
|
|
|
|
|
Maybe it's something specific to mssql then, I haven't work with it before so I'm not sure.
|

October 30th, 2012, 09:03 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
|
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, 02:12 AM
|
|
Contributing User
|
|
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68
Time spent in forums: 13 h 3 m 55 sec
Reputation Power: 8
|
|
|
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 .
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|