[dba-SQLServer]Field Sizes

Mike and Doris Manning mikedorism at ntelos.net
Mon Oct 6 15:36:09 CDT 2003


Pardon me, but I need to correct myself.

Char -- fixed width -- padded with spaces
VarChar -- variable width -- no padding
NChar -- fixed width allowing for Unicode characters -- padded with spaces
NVarChar -- variable width allowing for Unicode characters -- no padding

>From SQL BOL:

The Unicode specification defines a single encoding scheme for most
characters widely used in businesses around the world. All computers
consistently translate the bit patterns in Unicode data into characters
using the single Unicode specification. This ensures that the same bit
pattern is always converted to the same character on all computers. Data can
be freely transferred from one database or computer to another without
concern that the receiving system will translate the bit patterns into
characters incorrectly.

One problem with data types that use 1 byte to encode each character is that
the data type can only represent 256 different characters. This forces
multiple encoding specifications (or code pages) for different alphabets
such as European alphabets, which are relatively small. It is also
impossible to handle systems such as the Japanese Kanji or Korean Hangul
alphabets that have thousands of characters.

Each MicrosoftR SQL ServerT collation has a code page that defines what
patterns of bits represent each character in char, varchar, and text values.
Individual columns and character constants can be assigned a different code
page. Client computers use the code page associated with the operating
system locale to interpret character bit patterns. There are many different
code pages. Some characters appear on some code pages, but not on others.
Some characters are defined with one bit pattern on some code pages, and
with a different bit pattern on other code pages. When you build
international systems that must handle different languages, it becomes
difficult to pick code pages for all the computers that meet the language
requirements of multiple countries/regions. It is also difficult to ensure
that every computer performs the correct translations when interfacing with
a system using a different code page.

The Unicode specification addresses this problem by using 2 bytes to encode
each character. There are enough different patterns (65,536) in 2 bytes for
a single specification covering the most common business languages. Because
all Unicode systems consistently use the same bit patterns to represent all
characters, there is no problem with characters being converted incorrectly
when moving from one system to another. You can minimize character
conversion issues by using Unicode data types throughout your system.

Doris Manning
Database Administrator
Hargrove Inc.
www.hargroveinc.com

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of John Colby
Sent: Monday, October 06, 2003 1:18 PM
To: dba-sqlserver at databaseadvisors.com
Subject: RE: [dba-SQLServer]Field Sizes


>It does if you use varchar (pads the rest with spaces) but it does not 
>if
you use nvarchar.

Which begs the question, why use varchar?  Faster than Nvarchar?


John W. Colby
www.colbyconsulting.com

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com]On Behalf Of Mike and
Doris Manning
Sent: Monday, October 06, 2003 1:16 PM
To: dba-sqlserver at databaseadvisors.com
Subject: RE: [dba-SQLServer]Field Sizes


It does if you use varchar (pads the rest with spaces) but it does not if
you use nvarchar.

Doris Manning
Database Administrator
Hargrove Inc.
www.hargroveinc.com


-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of John Colby
Sent: Monday, October 06, 2003 9:59 AM
To: SQLServer
Subject: [dba-SQLServer]Field Sizes


Access stores text and memo data using the exact amount needed (plus
pointers) , i.e. even though the text field says 255 characters if the
string is 10 characters, 10 characters are used for storage.

Does SQL Server work this way of is space "reserved" for the stated size of
the field?

John W. Colby
www.colbyconsulting.com


_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com

_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com




_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com



More information about the dba-SQLServer mailing list