Page 147 - Informatics_Practices_Fliipbook_Class12
P. 147

4.3.1 Data Types

            Attributes of a table describe the data that will be stored in the table. The data type indicates the domain of values for an
            attribute. A data type may be of one of the several permissible types.
            Below we describe some important data types:

            Numeric
            The following data types may be used to specify that an attribute can contain numeric data:


                  Subtype          Width               Valid examples                     Invalid examples
             INT or INTEGER 32-bit           0                                  1,23,456  (punctuation  characters
                                                                                not allowed)
                                             -0
                                                                                29-01-22  (punctuation  characters
                                             1234
                                                                                not allowed)
                                             1234567890
                                                                                -2147483649 (beyond valid range)
                                             -1234567890
                                             123.45  (digits  to the right of the   2147483648 (beyond valid range)
                                             decimal point are truncated)       98765432100.1234  (beyond  valid
                                                                                range)

             SMALLINT           16-bit       0                                  1,23,456  (punctuation  characters
                                                                                not allowed)
                                             -0
                                             1234                               29-01-22  (punctuation  characters
                                                                                not allowed)
                                             -32768
                                                                                -32769 (beyond valid range)
                                             32767
                                             123.45  (digits  to the right of the   32768 (beyond valid range)
                                             decimal point are truncated)       987654321.1234 (beyond valid range)

             DECIMAL(L, D) Fixed point       For type DECIMAL(6,2)              For type DECIMAL(6,2)
                                decimal,     1234                               12345  12345.12
                                with total L                                            12345678.1
                                digits and D   -123456
                                digits after   1234.56                                  -12345.1234
                                decimal      1234.56789                                 -12345678.12
                                             (rounded to  1234.57)              In all above cases, it is invalid as it has
                                             -1234.56789                        more than four digits in the integer part
                                             (rounded to -1234.57)

             FLOAT(p)           Floating     For type FLOAT(8)                                   -
                                point        1234


                                             -123456
                                             1234.56
                                             1234.56789 (rounded to 1234.57)

                                             -1234.56789
                                             (rounded to -1234.57)






                                                                                        Database Query using SQL  133
   142   143   144   145   146   147   148   149   150   151   152