What are the basic data types

            The data type defines the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored. Sharing some basic data types and its usages.

1)TINYINT / SMALLINT/ MEDIUMINT/ INT / BIGINT
2) FLOAT / DECIMAL
3) CHAR / VARCHAR / TEXT
4) DATETIME / TIMESTAMP

TINYINT / SMALLINT/ MEDIUMINT/ INT / BIGINT

  • each of these handles integers, including negatives
  • differ on max values they handle + storage size
  • listed here in order of size (TINYINT is smallest)
  • generally, use the smallest that gets the job done

FLOAT / DECIMAL
  • FLOAT and DECIMAL handle decimals places
  • FLOAT is 'approximate'
  • DECIMAL is an exact data type
  • Use DECIMAL for dollars and cents to get better precision

CHAR / VARCHAR / TEXT
  • All of these data types store string values
  • CHAR and VARCHAR can handle up to 255 characters
  • CHAR(30): stores 30 characters, including trailing spaces
  • VARCHAR(30): UP TO 30 characters (no trailing spaces)
  • TEXT can handle ~65.5k characters (good for long strings)

DATETIME / TIMESTAMP
  • Both handle times, to the second
  • DATETIME: YYYY-MM-DD HH:MM:SS
  • TIMESTAMP: YYYYMMDDHHMMSS