Click here to Skip to main content
15,888,126 members
Articles / Programming Languages / SQL
Tip/Trick

General rules on selecting Data Types of SQL Server

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
23 Nov 2011CPOL1 min read 14.3K   1  
1.Use the smallest possible columnsizes. The smaller the columnsize, the less the amount of data that SQL Server has to store and process, and the faster SQL Server will be able to read and write the data. In addition, the narrower the column, the faster a sort will be performed onthat column.

2.Use the smallest possible data type that will hold your data for a column. For example, if you are going to be storing numbers from 1 to 99 in a column, you would be better off selecting the TINYINT data type instead of the INT data type.
For numeric data, it is better to use a numeric data type such as INTEGER rather than using VARCHAR or CHAR, since numeric data types generally require less space to hold numeric values then character data types. Also, if numeric data is stored as characters, it will have to be converted to numbers to be used in calculations. Smaller columns can improve performance when the columns are searched, joined with other columns, or sorted.

3.FLOATs or REALs should not be used to define primary keys. Integer data types are most commonly used for primary keys. Avoid selecting the fixed-length columns—CHAR or NCHAR—if your columnwill have a lot of NULLs. The NULL ina CHAR or NCHAR field will take up the entire fixed length of 255 characters. This is a large waste of space and reduces SQL Server’s overall performance.

4.If you are going to be using a column for frequent sorts, consider an integer-based column rather than a character-based column. SQL Server sorts integer data faster than character data.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --