Click here to Skip to main content
11,641,209 members (63,284 online)
Click here to Skip to main content

Tagged as

General rules on selecting Data Types of SQL Server

, 23 Nov 2011 CPOL 10.3K 1
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Ahmed Naqibul Arefin
Software Developer
Bangladesh Bangladesh
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150731.1 | Last Updated 23 Nov 2011
Article Copyright 2011 by Ahmed Naqibul Arefin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid