Tuesday, 12 May 2015

Auto increment in mysql query

Auto increment

Auto increment can be any data type Tinyint (signed , unsigned), smallint...

auto increment column automatically add the unique value to the records.   

CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM;

INSERT INTO animals (name) VALUES
('dog'),('cat'),('penguin'),
('lax'),('whale'),('ostrich');

SELECT * FROM animals;


TINYINT Signed          
 -128 to 127 1 byte               
Unsigned: 0 to 255
SMALLINT Signed
-32768 to 32767 2 bytes     
Unsigned: 0 to 65535
MEDIUMINT Signed    
-8388608 to 8388607 3 bytes      
Unsigned: 0 to 16777215
INT Signed: 
-2147483648 to 2147483647 4 bytes
Unsigned: 0 to 4294967295
INTEGER Sane values as the INT data type. (INTEGER is 4 bytes  a synonym for INT.)
BIGINT Signed: -9223372036854775808 to 8 bytes
9223372036854775807  Unsigned: 0 to 1844674407370u551615

No comments:

Post a Comment