ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion 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 April 26th, 2005, 01:57 PM
NightVa NightVa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 67 NightVa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 31 m 33 sec
Reputation Power: 5
Will a query of query update two tables that are joined?

Hi all,

I'm using an update query that adds a record to the employeeInfo table. I've taken the advice of certain CF masters in this forum and I've normalized my database (at least the employee section) and broken my one data table with comma lists into (hold on to something) 4 tables. One table actually joins the other three.

What's the best use of SQL to not only update the employeeInfo table but the employeeGymConnect table which is the intermediate table for joining all the other tables.

The position, gymname,programsAssocWith all have foriegn keys in the employeeGymConnect table.

I thought I might use a query inside a query to do both updates at the same time but I still can't be sure that the new record in the employeeInfo table will be the one updated in the employeeGymConnect table.

I hope I explained this clear enough. Help?

Nathan

Reply With Quote
  #2  
Old April 26th, 2005, 02:06 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 23
Send a message via AIM to bocmaxima
Quote:
Originally Posted by NightVa
I thought I might use a query inside a query to do both updates at the same time but I still can't be sure that the new record in the employeeInfo table will be the one updated in the employeeGymConnect table.

I don't even understand how you would do this. You can run a SELECT sub-query on an UPDATE or INSERT query, but you can't run an UPDATE sub-query on one. The logic just doesn't work.
The syntax of an UPDATE or INSERT query provides for only one table name. Feel free to play around with it, but I've never seen a way to do an UPDATE or INSERT through multiple tables without running multiple queries.

Reply With Quote
  #3  
Old April 26th, 2005, 03:28 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Just write two queries, one for each table, and wrap them in a <cftransaction> tag so that they execute or fail as a single unit.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #4  
Old April 26th, 2005, 08:53 PM
NightVa NightVa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 67 NightVa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 31 m 33 sec
Reputation Power: 5
I guess I'm not wrapping my head around the logical sequence of events for updating two table that are joined.

I need to be sure the correct info is updated in both tables for one record. Since one table creates a AutoNumber for each new employee record and then the empGymConnect table needs to be updated but ONLY after this new record in added in the emp table.

What would the SQL look like?

Nathan

Reply With Quote
  #5  
Old April 26th, 2005, 09:14 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
Insert the data into the base table, select the data back out if necessary to get the primary key, then do one ore more additional inserts into the related tables. Use cftransaction around the whole set of queries. Make sense?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Will a query of query update two tables that are joined?


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT