July 10, 2009 at 8:05 am
I am running this query in the query analyzer:
update claimfile set recreason = ''
The computer is not a dog but it has been running for 3 hours - is there a better way to change a field to be "blank" instead of "null" in 3 million records?
July 10, 2009 at 8:10 am
if you just want to change that field to an empty string, maybe dropping the column and then making a new column with the default value of empty string would be faster? i think it would be faster than 3 hours for sure, though i could be wrong.
July 10, 2009 at 8:13 am
Exec sp_who
Look at the blk column if this is zero it means no blocking, I'm betting your process is being blocked.. You need to know the SPID of the long running process, SSMS will tell you this information, it is near the bottom right where it shows your login name something like "domain\username (55)", that number is the SPID.
I am fairly sure you are getting blocked..
CEWII
July 10, 2009 at 8:14 am
with massive updates like that I think it is a lot easier to undo or stop if you did the updates in batches, instead of trying to do the whole table.
something like this:
SET ROWCOUNT 50000
WHILE 1=1
BEGIN
UPDATE myTable
SET SOMEVALUE = ''
WHERE SOMEVALUE = NULL
IF @@ROWCOUNT = 0
BREAK
END
SET ROWCOUNT 0
Lowell
July 10, 2009 at 8:26 am
Elliot W,
there is one process in the blk table that has a number - the command is "update", the pid is 53 but I am showing 54 as mine but that has to be it !
Pretty sure it is what you are referring to - what does "being blocked" mean and what could I do about it?
Am I stuck or do I wait it out?
Thanks
July 10, 2009 at 9:09 am
The way that is read is the row that has the value over zero is being blocked by the SPID listed.
I'm going to cut out a lot of columns for this..
[font="Courier New"]
spid blk
51 0
52 0
53 55
54 0
55 52
[/font]
In this case we see that 53 is blocked by 55, and 55 is blocked by 52, this makes 52 the "head blocker", we need to do something about 52, often times if I know what it is I just kill it.
You can often determine what it a spid is running by using:
DBCC INPUTBUFFER ( [spid] )
Back to our example, if we resolve the issue with 52 it will likely break 55 loose and let it finish, but if it doesn't then we may need to kill it too.
The long and short answer is blk means this spid blocked by spid listed.
CEWII
July 10, 2009 at 9:27 am
On my machine is says spid 53 and blk 53
so it looks like it is blocking itself?
July 10, 2009 at 9:34 am
On very large tables, updating the table in batches is the best way to avoid blockings. I'd go with Lowell's suggestion to update your table in batches. You can definately control the batch size as defined in the first line.
July 10, 2009 at 9:39 am
Could that technique work if I wanted to automate the process?, that is, make sure the whole table was done before I went on to another query. ( this blanking out is part of a 3-step query where this is the first step.
Or would I have to make this a manual process
Thanks
July 13, 2009 at 5:51 pm
kevinwinters (7/10/2009)
On my machine is says spid 53 and blk 53so it looks like it is blocking itself?
Do you have triggers on this table?
I have to admit I've never seem it blocking itself without triggers..
CEWII
July 13, 2009 at 7:40 pm
No, no triggers, I simply use SQL Server to do some number crunching through queries and have been trying to automate the process. The query actually took 11 hours to finally complete. I guess it is going to be better to automate the creating of the column and setting the default value to empty string - can you tell me what that command would be ?
Thanks
July 14, 2009 at 5:25 am
well, not really sure what you mean by automate it, but if you want the script to create a column with a default value, it's:
ALTER TABLE [TableName] ADD [ColumnName] DEFAULT [DefaultValue]
July 14, 2009 at 8:59 am
Do you have triggers on this table?
I have to admit I've never seem it blocking itself without triggers.
That is a very good question. I have seen this type of behavior when there is a trigger on a table updating an audit column for any time any other column is updated.
July 14, 2009 at 3:02 pm
Kramaswamy,
When I do this: alter table test add testcolumn text default ''
I get a colum with "null" instead of blank
This isn't what I wanted, what did I do wrong?
July 14, 2009 at 3:28 pm
Viewing 15 posts - 1 through 15 (of 25 total)
You must be logged in to reply to this topic. Login to reply