SlideShare a Scribd company logo
Overview of MySQL
Data types
What is a data type?
 A data type specifies a particular type of data, such as integer,
floating-point, Boolean etc…….
 A data type also specifies the possible values for that type, the
operations that can be performed on that type and the way the
values of that type are stored
MySQL data types
 Supports a number of SQL standard data types in various
categories.
 Has three main categories
 Numeric types
 DATE and TIME type
 String
MySQL Numeric types
 MySQL supports all standard SQL numeric data types
 Include
 INTEGER
 SMALLINT
 DECIMAL
 NUMERIC
MySQL Numeric types cont.…
 Also supports approximate numeric data types
 FLOAT
 REAL
 DOUBLE PRECISION
Integer types
 SQL standard integer types INTEGER(or INT) and SMALLINT are
supported by MySQL.
 Also supports the integer types;
 TINYINT
 MEDIUMINT
 BIGINT
Required storage and range
Type Length in
bytes
Minimum
Value
(Signed)
Max Val
(Signed)
Min Val
(Unsigned)
Max Val
(Unsigned)
TINYINT 1 -128 127 0 255
SMALLINT 2 -32768 32767 0 65535
MEDIUMINT 3 -8388608 8388607 0 16777215
INT 4 -2147483648 2147483648 0 429497295
BIGINT 8 -
922337203685
4775808
922337203685
4775808
0 184467440737
09551615
Floating-Point Types
 The FLOAT and DOUBLE types represent approximate numeric data
values.
 MySQL allows non standard syntax
 FLOAT(M,D)
 REAL(M,D)
 Here values can be stored up to M digits in total where D represent
decimal point
Required storage and range
Type Length in byte Minimum value
(Signed)
Maximum
value(Singed)
Minimum Value
(Unsigned)
Maximum
Value
(Unsigned)
FLOAT 4 -
3.402823466E+3
8
-1.175494351E-
38
1.175494351E-
38
3.402823466E+3
DOUBLE 8 -
1.797693134862
3
157E+ 308
-
2.225073858507
20
14E- 308
0, and
2.225073858507
20
14E- 308
1.797693134862
315
7E+ 308
Fixed-Point Types
 Used to preserve exact precision
 For example currency data.
 DECIMAL and NUMERIC type store exact numeric data values
More in fixed point type
 DECIMAL(5,2) be able to store any value with five digits and 2
decimals
 Value range will be -999.99 to 999.99
 DECIMAL(M) is equivalent to DECIMAL(M,0)
 DECIMAL is equivalent to DECIMAL(M,0)
 MySQL supports both of these forms
 Represent DATE, TIME, DATETIME, TIMESTAMP and YEAR
 Each type has range of valid values as well as a zero values.
MySQL Date and Time Types
DATETIME, DATE, and TIMESTAMP
Types
Types Description Display Format Range
DATETIME Use when you need
values containing both
date and time
information
YYYY-MM-DD
HH:MM:SS
'1000-01-01 00:00:00' to
'9999-12-31 23:59:59'.
DATE Use when you need only
date information.
YYYY-MM-DD '1000-01-01' to '9999-
12-31'.
TIMESTAMP Values are converted
from the current time
zone to UTC while
storing, and converted
back from UTC to the
current time zone
when retrieved
YYYY-MM-DD
HH:MM:SS
'1970-01-01 00:00:01'
UTC to '2038-01-19
03:14:07' UTC
Time Type
 Fetch and display time value in ‘HH:MM:SS’ or ‘HHH:MM:SS’ format
 Range : from ‘-838:59:59’ to ‘839:59:59’.
 MySQL explain abbreviated TIME values with colons as the time of
the day.
 Suppose ’09:10’ means ’09:10:00’ not ’00:09:10’
 Two right most digits represent seconds.
Time Type cont.
 Fro example we think ‘0910’ and 0910 as meaning 09:10:00, i.e. 10
minutes after 9 o’clock but reality is MySQL understand them as
00:09:10, i.e. 9 minutes and 10 second.!
Year Type
 Year type is 1-byte type represent year values.
 Can be declared as YEAR(2) or YEAR(4) to specify a display width 2
or 4 characters
 Default width is four characters.
 YEAR(4) and YEAR(2) have different display format, but have the
same range of values.
 For 2-digt format, MySQL displays only the last two digits; For
example, 70 (1970) or 2070
Year Type cont.
 We also can specify YEAR values in a variant formats;
String length Range
4-digit string ‘1901’ to ‘2155’
4-digit number 1901 to 2155
1- or 2-digit string ‘0’ to ‘99'. Values in the ranges '0'
to '69' and '70' to '99' are
converted to YEAR values in the
ranges 2000 to 2069 and 1970 to
1999
1- or 2-digit number 1 to 99. Values in the ranges 1 to 69
and 70 to 99 are converted to
YEAR values in the ranges 2001 to
2069 and 1970 to 1999.
String Types
 The string types:
 CHAR
 VARCHAR
 BINARY
 VARBINARY
 BLOB
 TEXT
CHAR and VARCHAR Types
 CHAR and VARCHAR types are similar, but differ in the way they are
stored and retrieved.
 They also differ in maximum length.
CHAR and VARCHAR Types cont.
Type Description Display format Range in
characters
CHAR Contains non-
binary strings.
Length is fixed as
you declare while
creating a table.
When stored, they
are right-padded
with spaces to the
specified length
Trailing spaces are
removed.
The length can be
any value from 0
to 255.
VARCHAR Contains non-
binary strings.
Columns are
variable-length
strings
As stored. A value from 0 to
255 before MySQL
5.0.3, and 0 to
65,535 in 5.0.3 and
later versions
BINARY and VARBINARY Types
 Similar to CHAR and VARCHAR
 But they contain binary strings rather than non binary strings.
Type Description Range in bytes
BINARY Contains binary strings 0 to 255
VARBINARY Contain binary strings. A value from 0 to 255 before
MySQL 5.0.3, and 0 to 65,535 in
5.0.3 and later versions
BLOB and TEXT types
 A BLOB is a binary large object that can hold a variable amount of
data.
 Four types of BLOBS (differ only the maximum length)
 TINYBLOB
 MEDIUMBLOB
 LONGBLOB
BLOB and TEXT types cont.
 Four TEXT types
 TINYTEXT
 TEXT
 MEDIUMTEXT
 LONGTEXT
 Corresponding blob types and text type have the same maximum
length
BLOB and TEXT types cont.
Type Description Category Range
BLOB Large binary object that
containing a variable amount
of data. Values are treated as
binary strings. You don't need
to specify length while
creating a column
TINYBLOB Maximum
length of 255
characters.
MEDIUMBLOB Maximum
length of
16777215
characters.
LONGBLOB Maximum
length of
4294967295
characters
TEXT Values are treated as
character strings having a
character set
TINYBLOB Maximum
length of 255
characters.
MEDIUMBLOB Maximum
length of
16777215
Reference
 http://dev.mysql.com/doc/refman/5.0/en/data-types.html
 http://www.tutorialspoint.com/mysql/mysql-data-types.htm
 http://www.webdevelopersnotes.com/tutorials/sql/mysql_database
_introduction_mysql_beginners_tutorial.php3

More Related Content

PPTX
VLOOKUP HLOOKUP INDEX MATCH
PPTX
Types of attacks
PPTX
introdution to SQL and SQL functions
PDF
Chapter 4 Structured Query Language
PDF
Exception Handling
PPT
Scrum ppt
PPTX
Structure of Telephone System.pptx
VLOOKUP HLOOKUP INDEX MATCH
Types of attacks
introdution to SQL and SQL functions
Chapter 4 Structured Query Language
Exception Handling
Scrum ppt
Structure of Telephone System.pptx

What's hot (20)

PPTX
SQL - DML and DDL Commands
PDF
SQL Overview
PPTX
Aggregate function
PPTX
Basic SQL and History
PPTX
Dbms and rdbms ppt
PPTX
Sql subquery
ODP
Ms sql-server
PPT
Aggregate functions
PPT
MYSQL.ppt
PPT
MySQL Functions
PPTX
SQL Queries Information
PPT
Sql ppt
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
PPT
1 - Introduction to PL/SQL
PPTX
DATABASE CONSTRAINTS
PPTX
STRUCTURE OF SQL QUERIES
PPTX
Attributes
PDF
Enhanced Entity-Relationship (EER) Modeling
PPTX
SQL(DDL & DML)
SQL - DML and DDL Commands
SQL Overview
Aggregate function
Basic SQL and History
Dbms and rdbms ppt
Sql subquery
Ms sql-server
Aggregate functions
MYSQL.ppt
MySQL Functions
SQL Queries Information
Sql ppt
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
1 - Introduction to PL/SQL
DATABASE CONSTRAINTS
STRUCTURE OF SQL QUERIES
Attributes
Enhanced Entity-Relationship (EER) Modeling
SQL(DDL & DML)
Ad

Similar to MySQL Data types (20)

DOCX
mysql datatype______________________.docx
PPTX
2.0 sql data types for my sql, sql server
PDF
UNIT 3 SQL 10.pdf ORACEL DATABASE QUERY OPTIMIZATION
PPTX
session_2 on database mysql databaseds from file to
PPTX
2018 02 20_biological_databases_part2_v_upload
PPTX
2016 02 23_biological_databases_part2
DOCX
Sql data types for various d bs by naveen kumar veligeti
PPTX
2017 biological databasespart2
PDF
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdf
PPTX
unit 1_unit1_unit1_unit 1_unit1_unit1_ ppt.pptx
PPTX
unit 1_unit1_unit1_unit 1_unit1_unit1_ ppt.pptx
PPTX
2019 02 21_biological_databases_part2_v_upload
PPTX
advanced mySQL Database tutorials and RDBMS tutorials.pptx
PPTX
unit 1 ppt.pptx
PPTX
SQL Commands Part 1.pptx
DOC
Field datatypes
PPTX
Unit 5-hive data types – primitive and complex data
PPTX
SQL (Basic to Intermediate Customized 8 Hours)
PPTX
Sql Basics And Advanced
mysql datatype______________________.docx
2.0 sql data types for my sql, sql server
UNIT 3 SQL 10.pdf ORACEL DATABASE QUERY OPTIMIZATION
session_2 on database mysql databaseds from file to
2018 02 20_biological_databases_part2_v_upload
2016 02 23_biological_databases_part2
Sql data types for various d bs by naveen kumar veligeti
2017 biological databasespart2
Simple Queriebhjjnhhbbbbnnnnjjs In SQL.pdf
unit 1_unit1_unit1_unit 1_unit1_unit1_ ppt.pptx
unit 1_unit1_unit1_unit 1_unit1_unit1_ ppt.pptx
2019 02 21_biological_databases_part2_v_upload
advanced mySQL Database tutorials and RDBMS tutorials.pptx
unit 1 ppt.pptx
SQL Commands Part 1.pptx
Field datatypes
Unit 5-hive data types – primitive and complex data
SQL (Basic to Intermediate Customized 8 Hours)
Sql Basics And Advanced
Ad

MySQL Data types

  • 2. What is a data type?  A data type specifies a particular type of data, such as integer, floating-point, Boolean etc…….  A data type also specifies the possible values for that type, the operations that can be performed on that type and the way the values of that type are stored
  • 3. MySQL data types  Supports a number of SQL standard data types in various categories.  Has three main categories  Numeric types  DATE and TIME type  String
  • 4. MySQL Numeric types  MySQL supports all standard SQL numeric data types  Include  INTEGER  SMALLINT  DECIMAL  NUMERIC
  • 5. MySQL Numeric types cont.…  Also supports approximate numeric data types  FLOAT  REAL  DOUBLE PRECISION
  • 6. Integer types  SQL standard integer types INTEGER(or INT) and SMALLINT are supported by MySQL.  Also supports the integer types;  TINYINT  MEDIUMINT  BIGINT
  • 7. Required storage and range Type Length in bytes Minimum Value (Signed) Max Val (Signed) Min Val (Unsigned) Max Val (Unsigned) TINYINT 1 -128 127 0 255 SMALLINT 2 -32768 32767 0 65535 MEDIUMINT 3 -8388608 8388607 0 16777215 INT 4 -2147483648 2147483648 0 429497295 BIGINT 8 - 922337203685 4775808 922337203685 4775808 0 184467440737 09551615
  • 8. Floating-Point Types  The FLOAT and DOUBLE types represent approximate numeric data values.  MySQL allows non standard syntax  FLOAT(M,D)  REAL(M,D)  Here values can be stored up to M digits in total where D represent decimal point
  • 9. Required storage and range Type Length in byte Minimum value (Signed) Maximum value(Singed) Minimum Value (Unsigned) Maximum Value (Unsigned) FLOAT 4 - 3.402823466E+3 8 -1.175494351E- 38 1.175494351E- 38 3.402823466E+3 DOUBLE 8 - 1.797693134862 3 157E+ 308 - 2.225073858507 20 14E- 308 0, and 2.225073858507 20 14E- 308 1.797693134862 315 7E+ 308
  • 10. Fixed-Point Types  Used to preserve exact precision  For example currency data.  DECIMAL and NUMERIC type store exact numeric data values
  • 11. More in fixed point type  DECIMAL(5,2) be able to store any value with five digits and 2 decimals  Value range will be -999.99 to 999.99  DECIMAL(M) is equivalent to DECIMAL(M,0)  DECIMAL is equivalent to DECIMAL(M,0)  MySQL supports both of these forms
  • 12.  Represent DATE, TIME, DATETIME, TIMESTAMP and YEAR  Each type has range of valid values as well as a zero values. MySQL Date and Time Types
  • 13. DATETIME, DATE, and TIMESTAMP Types Types Description Display Format Range DATETIME Use when you need values containing both date and time information YYYY-MM-DD HH:MM:SS '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. DATE Use when you need only date information. YYYY-MM-DD '1000-01-01' to '9999- 12-31'. TIMESTAMP Values are converted from the current time zone to UTC while storing, and converted back from UTC to the current time zone when retrieved YYYY-MM-DD HH:MM:SS '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC
  • 14. Time Type  Fetch and display time value in ‘HH:MM:SS’ or ‘HHH:MM:SS’ format  Range : from ‘-838:59:59’ to ‘839:59:59’.  MySQL explain abbreviated TIME values with colons as the time of the day.  Suppose ’09:10’ means ’09:10:00’ not ’00:09:10’  Two right most digits represent seconds.
  • 15. Time Type cont.  Fro example we think ‘0910’ and 0910 as meaning 09:10:00, i.e. 10 minutes after 9 o’clock but reality is MySQL understand them as 00:09:10, i.e. 9 minutes and 10 second.!
  • 16. Year Type  Year type is 1-byte type represent year values.  Can be declared as YEAR(2) or YEAR(4) to specify a display width 2 or 4 characters  Default width is four characters.  YEAR(4) and YEAR(2) have different display format, but have the same range of values.  For 2-digt format, MySQL displays only the last two digits; For example, 70 (1970) or 2070
  • 17. Year Type cont.  We also can specify YEAR values in a variant formats; String length Range 4-digit string ‘1901’ to ‘2155’ 4-digit number 1901 to 2155 1- or 2-digit string ‘0’ to ‘99'. Values in the ranges '0' to '69' and '70' to '99' are converted to YEAR values in the ranges 2000 to 2069 and 1970 to 1999 1- or 2-digit number 1 to 99. Values in the ranges 1 to 69 and 70 to 99 are converted to YEAR values in the ranges 2001 to 2069 and 1970 to 1999.
  • 18. String Types  The string types:  CHAR  VARCHAR  BINARY  VARBINARY  BLOB  TEXT
  • 19. CHAR and VARCHAR Types  CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved.  They also differ in maximum length.
  • 20. CHAR and VARCHAR Types cont. Type Description Display format Range in characters CHAR Contains non- binary strings. Length is fixed as you declare while creating a table. When stored, they are right-padded with spaces to the specified length Trailing spaces are removed. The length can be any value from 0 to 255. VARCHAR Contains non- binary strings. Columns are variable-length strings As stored. A value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions
  • 21. BINARY and VARBINARY Types  Similar to CHAR and VARCHAR  But they contain binary strings rather than non binary strings. Type Description Range in bytes BINARY Contains binary strings 0 to 255 VARBINARY Contain binary strings. A value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions
  • 22. BLOB and TEXT types  A BLOB is a binary large object that can hold a variable amount of data.  Four types of BLOBS (differ only the maximum length)  TINYBLOB  MEDIUMBLOB  LONGBLOB
  • 23. BLOB and TEXT types cont.  Four TEXT types  TINYTEXT  TEXT  MEDIUMTEXT  LONGTEXT  Corresponding blob types and text type have the same maximum length
  • 24. BLOB and TEXT types cont. Type Description Category Range BLOB Large binary object that containing a variable amount of data. Values are treated as binary strings. You don't need to specify length while creating a column TINYBLOB Maximum length of 255 characters. MEDIUMBLOB Maximum length of 16777215 characters. LONGBLOB Maximum length of 4294967295 characters TEXT Values are treated as character strings having a character set TINYBLOB Maximum length of 255 characters. MEDIUMBLOB Maximum length of 16777215
  • 25. Reference  http://dev.mysql.com/doc/refman/5.0/en/data-types.html  http://www.tutorialspoint.com/mysql/mysql-data-types.htm  http://www.webdevelopersnotes.com/tutorials/sql/mysql_database _introduction_mysql_beginners_tutorial.php3