Friday, March 23, 2012

Loop through tables names to use with update

Hi,

I have a group of tables that need to be updated with all the same colums name. I want to make a SP then pass the name of the table to it. Is this possiable? if so how do I do this

Thanks

Hi
can you try this
sp_msForEachTable @.command1='Update ? set colname = value'

you can also loop thu a cursor against this quey

select Table_Name from Information_Schema.Tables
|||

Please do not use the undocumented stored procedures. They are meant for internal use and any dependency that you take on undocumented SPs/functions is risky for your code. It can be broken anytime due to a change whether it is a service pack or new release. We do not make any guarantees on the interface/behavior of the undocumented SPs.

For this particular problem, you can use a cursor loop using INFORMATION_SCHEMA.TABLES or sys.tables views.

|||That is not the question, the question is how to write a loop that loops through tables, updating their row-definitions. Not just to display table-namessql

No comments:

Post a Comment