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. 
    
        
            
                
                    
                        
                            
                                | Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         itmasterw 
                                        Yak Posting Veteran 
                                         
                                        
                                        90 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2013-07-15 : 09:39:11
                                            
  | 
                                             
                                            
                                            | 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 itmITM | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     SwePeso 
                                    Patron Saint of Lost Yaks 
                                     
                                    
                                    30421 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-07-15 : 09:53:32
                                          
  | 
                                         
                                        
                                          Either thisALTER TABLE dbo.Table1 ALTER COLUMN Col1 VARCHAR(7) or thisALTER TABLE dbo.Table1 ALTER COLUMN Col1 VARCHAR(7) NOT NULL  N 56°04'39.26"E 12°55'05.63"  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     itmasterw 
                                    Yak Posting Veteran 
                                     
                                    
                                    90 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-07-15 : 10:08:39
                                          
  | 
                                         
                                        
                                          | 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 itmITM  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     James K 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    3873 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-07-15 : 11:24:30
                                          
  | 
                                         
                                        
                                          | 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.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     James K 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    3873 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-07-15 : 12:17:31
                                          
  | 
                                         
                                        
                                          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 itmITM
  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.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     itmasterw 
                                    Yak Posting Veteran 
                                     
                                    
                                    90 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-07-15 : 12:48:02
                                          
  | 
                                         
                                        
                                          Thanks, makes sence, I really appreaciate your help here guys.Thank you  ITM  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     SwePeso 
                                    Patron Saint of Lost Yaks 
                                     
                                    
                                    30421 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-07-15 : 13:24:27
                                          
  | 
                                         
                                        
                                          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"  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |   
     
     
            
              
	     |  
		
			
     
          
		 |