0

I am creating a table for that I am using a integer primary key field I am creating table as

CREATE TABLE `post` (
 `id`  int(100) NOT NULL AUTO_INCREMENT,
 `description` varchar(100),
   PRIMARY KEY (`id`)
 );

I read this Numeric Types. according to this we can store values in int and bigint less than 20 digits.

I would like to know about following

  1. What is the difference between id int(10) and id bigint(10)
  2. I have used id int(100) is there any problem.
  3. what data type should i use for above id(for id value 21 to 100 digits).
xrcwrn
  • 5,339
  • 17
  • 68
  • 129

1 Answers1

1

There is no meaning of defining digits for int type data as int(10), int(1), int(100) all are same as int and work as same. But int and bigint are different,bigint will occupy more spaces than int.Details are given below-

•tinyint    : 1 byte, -128 to +127 / 0 to 255 (unsigned)
•smallint   : 2 bytes, -32,768 to +32,767 / 0 to 65,535 (unsigned)
•mediumint  : 3 bytes, -8,388,608 to 8,388,607 / 0 to 16,777,215 (unsigned)
•int/integer: 4 bytes, -2,147,483,648 to +2,147,483,647 / 0 to 4,294,967,295 (unsigned)
•bigint     : 8 bytes, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 / 0 to 18,446,744,073,709,551,615 (unsigned)

Signed : can contain -ve values (it is default with integer type datatype)

unsigned : can not contain -ve values and have values from 0 to as per integer type

Note: The "unsigned" types are only available in MySQL

Rajesh
  • 786
  • 6
  • 12
Zafar Malik
  • 6,734
  • 2
  • 19
  • 30