2011-07-16 138 views
0
SELECT 
    name as [dbname] 
FROM 
    sys.databases 
    -- for each [dbname] 
    --update @[dbname] [dbo].[tb_Setting] -- this is the loop I need help with 
    SET 
    currentvalue = 'Powered by WaqarAttari' 
    WHERE 
    Title = 'MyFooter' and currentvalue = 'Powered by WaqarAttari' 

我想幫助在本節循環在SQL查詢的SQL Server 2008

-- for each [dbname] 
--update @[dbname] [dbo].[tb_Setting] -- this is the loop I need help with 

回答

2

可以使用無證sp_msforeachdb程序

EXEC sp_msforeachdb ' 
USE ? 
IF DB_ID() > 4 --ignore system databases 

    update [dbo].[tb_Setting] 
    SET 
    currentvalue = ''Powered by WaqarAttari'' 
    WHERE 
    Title = ''MyFooter'' and currentvalue = ''Powered by WaqarAttari'' 
    '