Another good tip for beginners -  remember that if you make a simple change in SQL Server Management Studio (SSMS) by opening up the table in design mode, you might see your entire IDE hang; the reason is because SQL Server could be doing a complete DML operation in the background, moving all of your rows into another table. Notice that I take a very large table – many rows – and alter a column to make it “NULLable”:

image

In profiler you can see that SQL Server escalated locking, created a new table, and the inserted rows from the existing table using HOLDLOCK and TABLOCKX hints. You’ll probably never be able to select out of, in this case, Tmp_tblCallLog, by the way. SSMS has chosen to move the data out into a new table, which may take a considerable time, my table here with about 50 million rows.

I know that there’s a better way of doing this, so I kill the process…SQL Server will roll back whatever it tried to do of course, so be prepared for this if you happen to go down this path:

image

The best way to change this column here is to simply do it in TSQL; you won’t get the huge background operation by SQL Server…profiler shows a simple change to the entire column without moving all of the data around, renaming temp tables, etc.

image

 

Thanks,

Lee

 

------------------------


Posted in: Beginner  Tags:
blog comments powered by Disqus

by Lee Everest, M.S.

Info

Poll

Do you use Azure or cloud in your organization?



Show Results

Ads

Search


Month List

Calendar

«  May 2012  »
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
View posts in large calendar

Tags

Disclaimer
The opinions, code, examples, et.al. expressed herein are my own personal opinions and do not represent my employer's view in any way, shape form, or fashion.  All code for demonstration purposes - no guarantees, either written or implied, are made.

© Copyright 2012 Lee Everest's SQL Server, etc. weblog