Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating two tables

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2007-12-21 : 14:55:49
I have two tables:

table 1
-------

code
description
colour
size
active

table 2
-------

code
location
sales_region
active

How can I, using SQL Server 2005, update both tables so that

colour = red
location = Wisconsin
size = medium
active = yes

where code = AL1

please?

table 1 has code as the primary key. table 2 has no index.

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-12-21 : 14:57:46
What have you tried so far?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-21 : 15:00:19
UPDATE Table1
SET colour = 'red',
size = 'medium',
active = 'yes'
WHERE code ='AL1'

UPDATE Table2
SET location = 'Wisconsin',
active = 'yes'
WHERE code ='AL1'

Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2007-12-21 : 15:50:30
Many thanks guys. My newbie brain did not realise that you can have more than one update operation per query.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-12-22 : 02:50:21
You could wrap some transaction management around your 2 update statements. You could also look at TRIGGERS

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -