
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What is the difference between int and integer in MySQL?
The int is the synonym of integer in MySQL 5.0. Here is the demo display both int and integer internally represents int(11).
Creating a table with int datatype
mysql> create table IntDemo -> ( -> Id int -> ); Query OK, 0 rows affected (1.04 sec)
Here is description of the table. The query is as follows
mysql> desc IntDemo;
The following is the output
+-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | Id | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 1 row in set (0.06 sec)
Look at the column type, which is int(11). Now it stores the same range as defined for integer. The query to insert record is as follows
mysql> insert into IntDemo values(2147483647); Query OK, 1 row affected (0.20 sec) mysql> insert into IntDemo values(-2147483648); Query OK, 1 row affected (0.42 sec)
Display all records from the table using select statement. The query is as follows
mysql> select *from IntDemo;
The following is the output
+-------------+ | Id | +-------------+ | 2147483647 | | -2147483648 | +-------------+ 2 rows in set (0.00 sec)
Creating a table with data type integer.
The query to create a table is as follows
mysql> create table IntegerDemo -> ( -> Id integer -> ); Query OK, 0 rows affected (0.93 sec)
Check the description of the table using desc command.
mysql> desc IntegerDemo;
The following is the output
+-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | Id | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 1 row in set (0.00 sec)
Insert record in the table using insert command. The integer takes the same range as int. The query is as follows
mysql> insert into IntegerDemo values(2147483647); Query OK, 1 row affected (0.11 sec) mysql> insert into IntegerDemo values(-2147483648); Query OK, 1 row affected (0.27 sec)
Display all records from the table using select statement. The query is as follows
mysql> select *from IntegerDemo;
The following is the output
+-------------+ | Id | +-------------+ | 2147483647 | | -2147483648 | +-------------+ 2 rows in set (0.00 sec)
- Related Articles
- Difference between an Integer and int in Java
- What is the difference between const int*, const int * const, and int const *?
- What is difference between int and const int& in C/C++?
- What is the difference between size_t and int in C++?
- What is the difference between int and Int32 in C#?
- Difference between MySQL BigInt(20) and Int(20)?
- What are the differences between an Integer and an int in Java?
- What is the difference between an int and a long in C++?
- Difference between const int*, const int * const, and int const * in C
- Difference Between int and long
- What is the difference between integer and floating point literals in Java?
- Difference between const int*, const int * const, and int const * in C/C++?
- What is the difference between SQL and MySQL?
- Difference between “int main()” and “int main(void)” in C/C++?
- In MySQL, what is the difference between SERIAL and AUTO_INCREMENT?
