Learning MSSQL? This tutorial will provide a solid introduction to what data types should be used in the more encountered situations, such as storing money data, dates, addresses, and more.
If you are new to using developing for databases like MSSQL, you probably have questions regarding what are the best data types to use in difficult situations. I’m going to show you my preferred choice depending on what I’m storing int he database. This post will help you decide what datatypes to use in different situations, such as when using zip-codes, email addresses, dates, and money.
int
Numbers that are going to grow exponentially (and do not have decimals) like id’s and primary keys in your database, use int.
smallint
For small fixed length numbers like zipcodes and ages, use smallint.
varchar
For text like names, email addresses, and states, use varchar. You should set the length, such as for states you could use varchar(2) to store the state abbreviation.
varchar(MAX)
When you don’t know the length of the text, such as for blog posts or long paragraphs, you should you varchar(MAX) so that you are not limited.
smalldatetime
For dates, smalldatetime is usually enough for 90% of programs, the only thing it leaves out are fractions of seconds.
smallmoney
For the majority of currency and everyday dollar amounts (even for very large businesses), smallmoney is adequate.
bit
If your storing yes/no answers a bit is the best choice.
nvarchar
Need support for a multitude of characters on your multi-language site? use nvarchar to enable unicode character support.


