NigelRocks
asked on
Tricky SQL Query
Experts,
I'm performing a small migration in SQL Server and am wondering about how to update a common field in a set of tables.
The field that exists in about 10 tables in this database is LOCATION_ID. I want to do a global updatge that essentially says that for every LOCATION_ID field in all the tables with the word BUSINESS in the name to have the value changed from a 1 to a 2 (where the value is 1).
How would I do this?
I'm performing a small migration in SQL Server and am wondering about how to update a common field in a set of tables.
The field that exists in about 10 tables in this database is LOCATION_ID. I want to do a global updatge that essentially says that for every LOCATION_ID field in all the tables with the word BUSINESS in the name to have the value changed from a 1 to a 2 (where the value is 1).
How would I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
begin tran
begin try
update table1 set location_id=2 where location_id=1
update table2 set location_id=2 where location_id=1
update table3 set location_id=2 where location_id=1
update table4 set location_id=2 where location_id=1
update table5 set location_id=2 where location_id=1
...
commit
end try
begin catch
select error_number(), error_message()
rollback
end catch