469,942 Members | 2,516 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,942 developers. It's quick & easy.

How to create a IDENTITY column in MySQL?

Please help me to create an IDENTITY column in MySQL
May 24 '07 #1
3 113234
pradeep kaltari
102 Expert 100+
Please help me to create an IDENTITY column in MySQL
Hi,
You can create identity column as:
1: While creating a table-->
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE table_name
  2. (
  3.    id INTEGER AUTO_INCREMENT PRIMARY KEY
  4. )
  5.  
The identity column needs to be specified as a key (PRIMARY or UNIQUE)

2: If the table already exists-->
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE table_name ADD COLUMN id INTEGER AUTO_INCREMENT UNIQUE KEY;
  2.  
I hope this helps.

Regards,
Pradeep.
May 24 '07 #2
pbmods
5,821 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE table_name
  2. (
  3.    id INTEGER AUTO_INCREMENT PRIMARY KEY
  4. )
  5.  
The identity column needs to be specified as a key (PRIMARY or UNIQUE)
You can also do this:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE table_name
  2. (
  3.     id serial
  4. )
  5.  
Which is equivalent to:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE table_name
  2. (
  3.     id BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY auto_increment
  4. )
  5.  
May 25 '07 #3
Expand|Select|Wrap|Line Numbers
  1. create table table_name(id int(5), name varchar(30), primary key(id))
Jan 24 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by WhiteEagl | last post: by
2 posts views Thread by Omavlana Omav | last post: by
8 posts views Thread by shenanwei | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.