MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2012, 06:48 PM
flebber flebber is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68 flebber User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old October 29th, 2012, 07:36 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,944 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
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.
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #3  
Old October 29th, 2012, 08:03 PM
flebber flebber is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68 flebber User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old October 29th, 2012, 09:52 PM
flebber flebber is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68 flebber User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 3 m 55 sec
Reputation Power: 8
It's just got me really confused.

Reply With Quote
  #5  
Old October 30th, 2012, 06:31 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,944 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
Maybe it's something specific to mssql then, I haven't work with it before so I'm not sure.

Reply With Quote
  #6  
Old October 30th, 2012, 09:03 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 30 m 23 sec
Reputation Power: 4140
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #7  
Old October 31st, 2012, 02:12 AM
flebber flebber is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: Newcastle, Australia
Posts: 68 flebber User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 .

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SQL and Foreign keys and Data Use

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap