Home >> FAQs/Tutorials >> SQL Server FAQ

SQL Server FAQ - CHAR and VARCHAR - Character String Data Types

By: FYIcenter.com

(Continued from previous topic...)

What Are Character String Data Types?

Character string data types are used to store code page based character strings. SQL Server 2005 supports the following character string data types:

  • CHAR - Code page based character strings with a fixed length of n bytes defined as CHAR(n). The maximum length is 8,000 bytes. CHAR has a synonym of CHARACTER.
  • VARCHAR - Code page based character strings with a variable length of n bytes defined as VARCHAR(n). The maximum length is 8,000 bytes. VARCHAR has two synonyms of CHAR VARYING and CHARACTER VARYING. VARCHAR also has special form as VARCHAR(MAX), which can store up to 2^31-1 bytes.
  • TEXT - Code page based character strings with a variable length up to 2^31-1 (2,147,483,647) bytes. TEXT is equivalent to VARCHAR(MAX).

Here are some good examples of character string values:

PRINT 'Hello!    '; -- CHAR(10)
PRINT 'Hello!'; -- VARCHAR(10)
GO

(Continued on next topic...)

  1. What Is SQL Language?
  2. What Is Transact-SQL Language?
  3. What Is a Transact-SQL Statement?
  4. How To Start and End Transact-SQL Statements?
  5. How To Enter Comments in Transact-SQL Statements?
  6. What Is a Transact-SQL Statement Batch?
  7. What Happens to a Statement Batch If There Is a Compilation Error?
  8. How To Use GO Command in "sqlcmd"?
  9. How To Create User Messages with PRINT Statements?
  10. How Many Categories of Data Types Used by SQL Server?
  11. What Are Exact Numeric Data Types?
  12. What Are Approximate Numeric Data Types?
  13. What Are Date and Time Data Types?
  14. What Are Character String Data Types?
  15. What Are Unicode Character String Data Types?
  16. What Are Binary String Data Types?
  17. What Are the Differences between CHAR and NCHAR?
  18. What Are the Differences between CHAR and VARCHAR?
  19. What Are the Differences between DECIMAL and FLOAT?

Related Articles:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...