Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Column resizing

Author  Topic 

xpandre
Posting Yak Master

212 Posts

Posted - 2009-12-29 : 10:09:01
Hi,

We would be resizing a column from char(5) to nvarchar(100). And this column has an non clustered index as well.

Would resizing effect the index in any way? ( rowcount - 1/10th of a million)
Thanks

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-12-29 : 10:59:23
How were you going to go about this? Just by editing the table in management studio?


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

xpandre
Posting Yak Master

212 Posts

Posted - 2009-12-29 : 11:04:35
By command on SSMS

alter table xyz alter column abc nvarchar(100)
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-12-29 : 11:13:16
When you change the columns then what's happening behind the scenes is that temp table is made with the new column definitions and all the information is copied into it. The old table is then dropped and the indices and constraints are recreated on the new table.

Your non clustered index should be OK as a 100 length NVARCHAR is small enough.

You should run profiler some time while doing this. The steps are quite interesting.

Everything looks OK on my test table with 100,000 rows


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-12-29 : 11:14:42
If you do it that way (alter table) you'll have to drop and recreate the index.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-29 : 12:17:12
When you use ALTER TABLE command it does not use the temp table approach. I do not believe that you need to recreate the index either, but it may be faster to drop/create although I doubt it matters on such a small table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-29 : 12:25:17
Need to drop/recreate the index, else you'll get

Msg 5074, Level 16, State 1, Line 1
The index 'idx_name' is dependent on column 'xyz'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN abc failed because one or more objects access this column.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-29 : 12:28:02
I'm surprised it doesn't just expand/rebuild it for you.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-29 : 12:35:53
Me too. Maybe it's on purpose since the storage requirement for the index is changed, AND it has to be rebuilt since the row layout in page would be changed...thus MS wants to make sure there is manual intervention...

or it's just an oversight
Go to Top of Page

xpandre
Posting Yak Master

212 Posts

Posted - 2009-12-29 : 13:57:09
oh yes...we have to drop n recreate..

sheesh..should have checked before..Sorry for the trouble.

Would recreation of Index affect the performance of other queries accessing this columns? Would those queries re-create a new execution plan?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-29 : 14:42:22
Yes it'll impact performance if any queries used that index before the drop, but you really shouldn't worry too much for a table that small.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -