Page 248 - PYTHON-12
P. 248

12.12 SQL DATATYPES


               Just like any other  programming
               language, the facility of defining data                       MySQL Data
                                                                                types
               of  various  types is available  in SQL
               also.  SQL supports the following
               datatypes  for  the  specification  of
                                                                            Non-numeric or
               various  data-items  or  fields  of  a      Numeric                              Date and Time
                                                                                String
               relation/table.  In  SQL,  each  column
                                                                      Fig. 12.19: MySQL Datatypes
               of the table  is assigned a  datatype
               which conveys the kind of value that
               will be stored in the column.
                     Datatype          Syntax                              Description
                INTEGER (Numeric) INTEGER or       It stores/represents positive whole numbers up to 11 digits and
                                  integer          negative whole numbers up to 10 digits. The range of integer is from
                                                   –2,147,483,648 to 2,147,483,647.
                SMALLINT          SMALLINT         It is a 16-bit signed integer value that stores whole numbers in the range
                                                   -32768 to 32767. Its width is up to 5 digits.
                NUMERIC           NUMERIC(x,y)     Numbers are stored in the given format, where x is the total number of
                                                   digits and y is the number of places to the right of the decimal point. x must
                                                   include an extra place for the decimal point.
                                                   For example, Numeric(8,2)
                                                   In the given example, numeric datatype stores a number that has 5 places
                                                   before the decimal and 2 digits after the decimal and 1 digit place for the
                                                   decimal point. Numeric holds up to 20 significant digits. A negative number
                                                   holds one place for the sign, i.e., (–).
                DECIMAL           DECIMAL(x,y)     Numbers stored in the DECIMAL format, where x is the size, i.e., total
                                  Or               number of digits, and y is precision, i.e., it is the number of places to the
                                  DECIMAL(size,    right of the decimal point.
                                  precision)
                                                   For example, Decimal(8,2)
                                                   In the above example, decimal datatype stores a number that has 6 digits
                                  decimal point    before the decimal and 2 digits after the decimal.
                                                   Decimal holds up to 19 significant digits. A negative number uses one
                                                   place for its sign (–).











           Computer Science with Python–XII  12.18 CHARACTER  CHAR(x)  This datatype stores ‘x’ number of characters in the string which has a fixed



                (fixed length)
                                                   length. A maximum of 254 characters can be stored in a string. If you store
                                  or
                                  CHAR(size)
                                                   strings that are not as long as the ‘size’ or ‘x’ parameter value,the remaining
                                                   spaces are left unused. For example, if you specify CHAR(10), strings such
                                                   as “ram” and “technology” are each stored as 10 characters. However, a
                                                   student admission_no is 6 digits long in a school, so CHAR(6) would be
                                                   appropriate  to store the admission_no  of all  the students. This datatype
                                                   is suitable where the number of characters to store is fixed. The value for
                                                   CHAR data type has to be enclosed in single or double quotation marks.
   243   244   245   246   247   248   249   250   251   252   253