Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQL Server 2008 SQL查询中的循环_Sql Server_Sql - Fatal编程技术网

Sql server SQL Server 2008 SQL查询中的循环

Sql server SQL Server 2008 SQL查询中的循环,sql-server,sql,Sql Server,Sql,我想在此部分提供帮助 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

我想在此部分提供帮助

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'

您可以使用未记录的sp_msforeachdb过程

 -- for each [dbname]
 --update @[dbname] [dbo].[tb_Setting] -- this is the loop I need help with
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''
  '