1

Simple SQL syntax question. I'm writing a script to move data from an old schema to a new one. I have to switch off the integrity constraints when performing the move so my CASCASEs don't work. I want to update multiple tables with a new value like so:

UPDATE table1, table2 
SET table1.customer_id = 999, table2.customer_id = 999;
WHERE table1.customer_id = 3
AND table2.customer_id = 3 

what's the correct syntax though? Hopefully the above explains what I want to achieve? Thanks :).

1
  • Your syntax should also have worked -- once you removed the semicolon after 999. Commented Jul 3, 2013 at 17:08

1 Answer 1

4

Try this:

UPDATE table1
INNER JOIN table2 USING (customer_id)
SET table1.customer_id = 999, table2.customer_id = 999
WHERE table1.customer_id = 3

Never tried it with an update to the key columns like this, but this would work for other columns, so worth a try.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.