question

Akbar avatar image
Akbar asked

Updating a Record in a Table Against All SQL Server Databases

Hi All,

I just want to update a record in a table which exist in all the databases of a particular SQL Server 2008 instance. But while trying the below script i'm getting a error like "Incorrect syntax near 'tes1'."

--script DECLARE @command varchar(1000)

SELECT @command = 'IF ''?'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'')

BEGIN USE ?

UPDATE dbo.mytable SET mycolumn1=''test'' WHERE mycolumn=''tes1'''

EXEC sp_MSforeachdb @command

Please let me know is that anything wrong in the above script?

sql-server-2008sqlupdate
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered

You need an END statement since you have a BEGIN statement.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.