STRING AND BINARY TYPES
Differences between BINARY AND VARBINARY
BINARY1
Fixed-length binary data with a length of n bytes, where n is a value from 1 through 8,000. The storage size is n bytes.
VARBINARY
Variable-length binary data. n can be a value from 1 through 8,000.
Max indicates that the maximum storage size is 2^31-1 bytes.
The storage size is the actual length of the data entered + 2 bytes.
The data that is entered can be 0 bytes in length.
The ANSI SQL synonym for varbinary is binary varying.
Conclusion:
Use binary when the sizes of the column data entries are consistent.
Use varbinary when the sizes of the column data entries vary considerably.
Use varbinary(max) when the column data entries exceed 8,000 bytes.
Differences between CHAR AND VARCHAR
CHAR
Fixed-length. so any remaining space in the field is padded with blanks.
non-Unicode character data with a length of n bytes, n must be a value from 1 through 8,000. The storage size is n bytes
The SQL-2003 synonym for char is character.
VARCHAR
Variable-length, non-Unicode character data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes.
The storage size is the actual length of data entered + 2 bytes.
The data entered can be 0 characters in length.
The SQL-2003 synonyms for varchar are char varying or character varying.
For example, if you set a VARCHAR(100) datatype = 'Jen', then it would take up 3 bytes (for J, E, and N) plus 2 bytes, or 5 bytes in all.
Conclusion:
Use Char, When Using the fixed length data in column & data entries are consistent, like phone number
Use Varchar When using the variable length data in column & data entries vary considerably, like address
Differences between VARCHAR/VARCHAR(MAX) and NVARCHAR/NVARCHAR(MAX)
Varchar/Varchar(MAX)
Varchar(8000) stores a maximum of 8000 characters. Varchar(max) stores a maximum of 2 147 483 647 characters or 2GB.
Variable length Non-Unicode Characters data.
The storage size is the actual length of data entered + 2 bytes
The SQL-2003 synonyms for varchar are char varying or character varying.
NVarchar/NVarchar(MAX)
NVarchar(4000) stores a maximum of 4000 characters. Varchar(max) stores a maximum of 1 073 741 823 characters or 1GB.
Variable length Unicode Characters data.
The storage size, in bytes, is two times the number of characters entered + 2 bytes
The SQL-2003 synonyms for nvarchar are national char varying and national character varying.
Differences between NCHAR AND NVARCHAR
NCHAR
Fixed-length. so any remaining space in the field is padded with blanks.
Unicode character data with a length of n bytes, n must be a value from 1 through 4,000. The storage size is n bytes
The ISO synonyms for nchar are national char and national character.
NVARCHAR
Variable-length, non-Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2GB).
The storage size is in bytes, is two times the actual length of data entered+ 2 bytes
The ISO synonyms for nvarchar are national char varying and national character varying.
Conclusion:
Use nchar when the sizes of the column data entries are probably going to be similar.
Use nvarchar when the sizes of the column data entries are probably going to vary considerably.
Differences between NTEXT, TEXT AND IMAGE
NTEXT
Variable-length Unicode data with a maximum string length of 2^30 - 1 (1,073,741,823).
Storage size, in bytes, is two times the string length entered.
The ISO synonym for ntext is national text.
TEXT
Variable-length non-Unicode data in the code page of the server and with a maximum string length of 2^31-1 (2,147,483,647).
When the server code page uses double-byte characters, the storage is still 2,147,483,647 bytes.
Depending on the character string, the storage size may be less than 2,147,483,647 bytes.
IMAGE
Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes.
NUMERIC DATATYPES
Difference between Decimal[ (p[ ,s] )] and Numeric[(p[ ,s] )]
Fixed precision and scale numbers.
When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1.
The ISO synonyms for decimal are dec and dec(p, s).
Numeric is functionally equivalent to decimal.
p (precision)
The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point.
The precision must be a value from 1 through the maximum precision of 38.
The default precision is 18.
s (scale)
The maximum number of decimal digits that can be stored to the right of the decimal point.
Scale must be a value from 0 through p.
Scale can be specified only if precision is specified.
The default scale is 0; therefore, 0 <= s <= p.
Maximum storage sizes vary, based on the precision.
Precision Storage bytes
1 - 9 5
10-19 9
20-28 13
29-38 17
Difference between Float and Real
Data type: float
Range: - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308
Storage: Depends on the value of n
Data type: real
Range: - 3.40E + 38 to -1.18E - 38, 0 and 1.18E - 38 to 3.40E + 38
Storage: 4 Bytes
nvalue: 1-24
Precision: 7 digits
Storage size: 4 bytes
nvalue: 25-53
Precision: 15 digits
Storage size: 8 bytes
Differences between INT, BIGINT, SMALLINT and TINYINT
Data type: int
Range: -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647)
Storage: 4 Bytes
Data type: bigint
Range: -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)
Storage: 8 Bytes
Data type: smallint
Range: -2^15 (-32,768) to 2^15-1 (32,767)
Storage: 2 Bytes
Data type: tinyint
Range: 0 to 255
Storage: 1 Bytes
Conclusion:
The int data type is the primary integer data type in SQL Server.
The bigint data type is intended for use when integer values might exceed the range that is supported by the int data type.
bigint fits between smallmoney and int in the data type precedence chart.
Functions return bigint only if the parameter expression is a bigint data type.
SQL Server does not automatically promote other integer data types (tinyint, smallint, and int) to bigint.
Differences between MONEY and SMALLMONEY
Data type: money
Range: -922,337,203,685,477.5808 to 922,337,203,685,477.5807
Storage: 8 Bytes
Data type: money
Range: - 214,748.3648 to 214,748.3647
Storage: 4 Bytes
Conclusion:
The money and smallmoney data types are accurate to a ten-thousandth of the monetary units that they represent.