x

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?

more ▼

asked Jan 29, 2010 at 02:02 PM in Default

Akbar gravatar image

Akbar
55 3 3 3

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jan 29, 2010 at 02:48 PM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
98k 19 21 74

Oh thanks. I think i need to take a coffee:-)
Jan 29, 2010 at 02:56 PM Akbar
2nd set of eyes solves lots of problems.
Jan 29, 2010 at 03:34 PM Grant Fritchey ♦♦
So does a cup of coffee ;)
Jan 30, 2010 at 07:56 PM TimothyAWiseman
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1832
x712
x129

asked: Jan 29, 2010 at 02:02 PM

Seen: 1490 times

Last Updated: Jan 29, 2010 at 02:02 PM