Unix Technical Forum

Any easy way to change column length like varchar 30 to varchar 100?

This is a discussion on Any easy way to change column length like varchar 30 to varchar 100? within the SQL Server forums, part of the Microsoft SQL Server category; --> I would like to increase the length of the column from LOCNumber VARCHAR(30) DEFAULT '' to LOCNumber VARCHAR(100) DEFAULT ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 06:52 AM
sdowney717@msn.com
 
Posts: n/a
Default Any easy way to change column length like varchar 30 to varchar 100?


I would like to increase the length of the column from
LOCNumber VARCHAR(30) DEFAULT ''

to
LOCNumber VARCHAR(100) DEFAULT ''

without losing any data currently stored in the field.


And it has an index on it defined as
CREATE INDEX LOCIndex ON BookData(LOCNumber)

Thanks for any help.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 06:52 AM
Hugo Kornelis
 
Posts: n/a
Default Re: Any easy way to change column length like varchar 30 to varchar 100?

On 31 Jan 2005 07:05:21 -0800, sdowney717@msn.com wrote:

>
>I would like to increase the length of the column from
>LOCNumber VARCHAR(30) DEFAULT ''
>
>to
>LOCNumber VARCHAR(100) DEFAULT ''
>
>without losing any data currently stored in the field.


Hi sdowney,

Just use ALTER TABLE:

ALTER TABLE BookData
ALTER COLUMN LOCIndex varchar(100)

No need to re-specify the default - it won't be changed.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 06:53 AM
sdowney717@msn.com
 
Posts: n/a
Default Re: Any easy way to change column length like varchar 30 to varchar 100?

That works well, thanks very much
Do you know how to do this with MySQL as well?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 06:53 AM
sdowney717@msn.com
 
Posts: n/a
Default Re: Any easy way to change column length like varchar 30 to varchar 100?

Found it, you use this
ALTER TABLE BookData MODIFY COLUMN LOCNumber varchar(100)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:46 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com