4. Data types in SQL

                                            
  • Data Types are attribute that specifies the type of data that a particular column or variable can hold.
  • There are various data types some of them are as follows
    1. INT : Integer data type used to store whole number.
    2. VARCHAR: Variable length character data type used to store text strings.
    3. DECIMAL : used to store decimal number with fixed precision and scale.
    4. DATE: used to store data values 
    5. TIME: used to store time values.
    6. BOOLEAN: used to store Boolean values (i.e. true or false)
    7. FLOAT: used to store floating point number.
    8. CHAR: Fixed length character data type used to store text strings. 
    9. NCHAR: Fixed length Unicode character data type, used to store Unicode character strings.
    10. MONEY: Data type used to store monetary value with fixed precision of 4 decimal place. 
  • Difference between char, nchar, varchar and nvarchar 
    • Char and nchar are fixed length which will reserve storage space for number of characters you specify even if you don't use up all that space.
    • Varchar and nvarchar are variable-length which will only use up spaces for the characters you store. It will not reserve storage like char and nchar.
    • nchar and nvarchar take up twice as much storage space, so it may be wise to use them only if you need unicode support. 
    • char and varchar can store maximum of 8000 characters
    • nchar and nvarchar can store maximum of 4000 characters



Comments