Quantcast
Viewing all articles
Browse latest Browse all 15064

Update a field in multiple tables

Hey all,
We have a database with a number of tables that have a field that needs updating. The field name is the same across all tables and the value we need to update to will also be the same across all tables.

I have the following statement that retrieves all of the tables with said field, but I'd like to know how I can update the fields as well...
Code:

SELECT      t.name AS 'TableName'
FROM        sys.columns c
JOIN        sys.tables  t  ON c.object_id = t.object_id
WHERE      c.name = 'UpdatePath'
ORDER BY    TableName

I would like to do something like this (which does not work)...
Code:

UPDATE TableName SET UpdatePath = 'update'
where TableName in (
        SELECT      t.name AS 'TableName'
        FROM        sys.columns c
        JOIN        sys.tables  t  ON c.object_id = t.object_id
        WHERE      c.name = 'UpdatePath'
        ORDER BY    TableName)

Does anyone have any idea about how to do this?
Thanks
Kevin

Viewing all articles
Browse latest Browse all 15064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>