Groups | Blog | Home
all groups > sql server new users > december 2006 >

sql server new users : Need to populate multiple records


_adrian
12/27/2006 2:56:43 PM
is there a sql update query or similar that I could type out and run on the
fly somehow that would populate a specific field in all of the records of a
table with the same value? Thx

_adrian
12/27/2006 3:12:49 PM
thats an excellent point.. thanks a ton Roy

Roy Harvey
12/27/2006 6:04:25 PM
Without a WHERE clause restricting which rows are updated, an UPDATE
will always apply to all rows in a table.

UPDATE SomeTable
SET SomeColumn = 'some value'

Roy Harvey
Beacon Falls, CT

On Wed, 27 Dec 2006 14:56:43 -0800, "_adrian" <adrian @ test.com>
[quoted text, click to view]
Roy Harvey
12/27/2006 6:08:00 PM
In the case that some of the rows already have the value you want to
assign to all rows, this configuration is much preferred, as it only
updates rows that have to change.

UPDATE SomeTable
SET SomeColumn = 'some value'
WHERE SomeColumn <> 'some value'

Roy Harvey
Beacon Falls, CT

On Wed, 27 Dec 2006 18:04:25 -0500, Roy Harvey <roy_harvey@snet.net>
[quoted text, click to view]
Anthony Thomas
12/30/2006 9:51:22 PM
Be careful of this on large tables. In order to make the query efficient,
there would need to be an index on that column, but then, your update
statement would also have to update the index.

It certainly depends upon the situation, but in some cases, it would be
better to drop the index, update all rows for a column, and then rebuild the
index (if there was one originally) than to try to maintain both and do a
searched update.

Don't get me wrong. What Roy has suggested is very good advice. I am just
trying to caution you on its usage on larger tables, only because the size
of the update was never mentioned.

Sincerely,


Anthony Thomas


--

[quoted text, click to view]

AddThis Social Bookmark Button