SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 bytes in a varchar
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

itmasterw
Yak Posting Veteran

90 Posts

Posted - 07/15/2013 :  09:39:11  Show Profile  Reply with Quote
Hi,
I have been asked to change a field that is varchar(4) from 5 -7 bytes. I am not sure what this is, I know it is varchar(4) rith now what would I have to chane it to to make it 7 bytes?

thank you
itm

ITM

SwePeso
Patron Saint of Lost Yaks

Sweden
29910 Posts

Posted - 07/15/2013 :  09:53:32  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Either this
ALTER TABLE dbo.Table1 ALTER COLUMN Col1 VARCHAR(7)
or this
ALTER TABLE dbo.Table1 ALTER COLUMN Col1 VARCHAR(7) NOT NULL



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

itmasterw
Yak Posting Veteran

90 Posts

Posted - 07/15/2013 :  10:08:39  Show Profile  Reply with Quote
So just so I understand, if they say go from 5-7 bytes, it just means to change the varchar to 7? There isn't formula that I have to use or anything?
Thank you
itm

ITM

Edited by - itmasterw on 07/15/2013 11:25:13
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3326 Posts

Posted - 07/15/2013 :  11:24:30  Show Profile  Reply with Quote
VARCHAR takes up as many spaces as there are characters plus one or two bytes for storing the length. So if you have VARCHAR(4), that takes up UP TO 5 bytes. I guess that is what they meant when they said change it from 5 to seven bytes - but I am guessing here. Ask them exactly what they mean by 5 bytes for a VARCHAR(4) column. And ask them what their goal is - do they want to store maximum of 6 characters, or maximum of 7 characters.

In any case, what you will need to do is what Swepeso suggested. You may need to change the 7 to six perhaps. But ask questions first.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3326 Posts

Posted - 07/15/2013 :  12:17:31  Show Profile  Reply with Quote
quote:
Originally posted by itmasterw

So just so I understand, if they say go from 5-7 bytes, it just means to change the varchar to 7? There isn't formula that I have to use or anything?
Thank you
itm

ITM

I see you edited the question after I posted my reply. But I am not sure what the edit was, so repeating what I posted earlier:

there is no complex formula you have to use. You just need to get from them what they meant by "increase from 5 to 7" bytes, given that currently the column is VARCHAR(4). Depending on their answer, you would use Swepeso's query with a 6 or 7.
Go to Top of Page

itmasterw
Yak Posting Veteran

90 Posts

Posted - 07/15/2013 :  12:48:02  Show Profile  Reply with Quote
Thanks, makes sence, I really appreaciate your help here guys.
Thank you

ITM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29910 Posts

Posted - 07/15/2013 :  13:24:27  Show Profile  Visit SwePeso's Homepage  Reply with Quote
With VARCHAR(7) you can store up to 7 characters in that column.
What is stored on disk and on page is different. Then you have to add NULL-pointers, 2 bytes for variable start pointer and 2 bytes for variable length information.


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000