Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:26:34+00:00 2026-06-05T07:26:34+00:00

Possible Duplicate: How to update two tables in one statement in SQL Server 2005?

  • 0

Possible Duplicate:
How to update two tables in one statement in SQL Server 2005?

I have two tables and need to update one table and take effect to the other table.

These two tables are linked by a relationship

t1.col1 PK , t2.col1 FK   

t1                t2
_____________  _____________
|col1|  col2|  |col1 |col2 |            
|----|------|  |-----|-----|                             
|1   |  a   |  | 1   | d   |            
|2   |  b   |  | 2   | e   |            
|3   |  c   |  | 3   | f   |            
|____|______|  |_____|_____|

How I can update these two tables in one query in SQL Server 2008 ?

I want to do something like that

 Update College 
 Inner Join Class ON College.CollegeId = Class.CollegeId 
 set College.CollegeId = '33333333-3333-3333-3333-333333333333',
     Class.CollegeId = '33333333-3333-3333-3333-333333333333' 
 where 
     College.CollegeId = '071887ea-3c93-40ce-a112-3b849d352064' 

but I get an error:

incorrect syntax near the keyword “Inner”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:26:36+00:00Added an answer on June 5, 2026 at 7:26 am

    Whether you update 2 tables with one statement in one query on one connection or 2 tables with two statements in one query on one connection, it is the same thing really.

    You can set parameters to pass to the script then you only have to send the value once and run the script once which will in turn only use one connection.

    declare @OldCollegeID
    declare @NewCollegeID
    
    Update Class set CollegeID = @NewCollegeID
    where CollegeID = @OldCollegeID
    
    Update College set CollegeID = @NewCollegeID
    where CollegeID = @OldCollegeID
    

    However, I am guessing the reason you want to do this simultaniously is because you can’t update college first without updating class because of the relationship? Trying to Update College.CollegeID will result in error because of the foreign key Class.CollegeID. The same applies visa versa. Class.CollegeID will not be updatable unless the Class.CollegeID you are updating to exists in College.CollegeID. In this case I will suggest the following:

    Create Procedure UpdateCollegeID
    (
       declare @OldCollegeID varchar(100),
       declare @NewCollegeID varchar(100)
    )
    
    as
    
    declare @CollegeName varchar(100)
    declare @ClassName varchar(100)
    
    set @CollegeName = (select CollegeName from College where CollegeID = @OldCollegeID)
    set @ClassName = (select ClassName from Class where CollegeID = @OldCollegeID)
    
    Insert into College (CollegeID, CollegeName)
    Values(@NewCollegeID, @NewCollegeName)
    
    Insert into Class (ClassID, CollegeID)
    Values(@ClassID, @NewCollegeID, @ClassName)
    
    Delete from Class where CollegeID = @OldCollegeID
    Delete from College where CollegeID = @OldCollegeID
    

    This will update all your old college records with the new id and you wont have to worry. You might have to do something differently in your front end application to cater for this depending on what it is. Keeping it a stored procedure will allow you to exec it and everything will update to the parameters passed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to update two tables in one statement in SQL Server 2005?
Possible Duplicate: update one table with data from another Extreme SQL noob here. I
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I'm
Possible Duplicate: Is there a way to automatically update application on Android? I have
Is it possible to INSERT...ON DUPLICATE KEY UPDATE into a table on the current
Possible Duplicate: How to update GUI from another thread in C#? I have form
I have a table with data : id one two three four five six
Possible Duplicate: SQL - how to SELECT multiple tables and JOIN multiple rows from
I have two input textareas, and the second one is hidden. Is it possible
I have combined two different tables together, one side is named DynDom and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.