Please help me to create an IDENTITY column in MySQL
How to create a IDENTITY column in MySQL?
Collapse
X
-
Originally posted by kcravimssPlease help me to create an IDENTITY column in MySQL
You can create identity column as:
1: While creating a table-->
[code=sql]
CREATE TABLE table_name
(
id INTEGER AUTO_INCREMENT PRIMARY KEY
)
[/code]
The identity column needs to be specified as a key (PRIMARY or UNIQUE)
2: If the table already exists-->
[code=sql]
ALTER TABLE table_name ADD COLUMN id INTEGER AUTO_INCREMENT UNIQUE KEY;
[/code]
I hope this helps.
Regards,
Pradeep. -
Originally posted by pradeep kaltari[code=sql]
CREATE TABLE table_name
(
id INTEGER AUTO_INCREMENT PRIMARY KEY
)
[/code]
The identity column needs to be specified as a key (PRIMARY or UNIQUE)
[code=mysql]
CREATE TABLE table_name
(
id serial
)
[/code]
Which is equivalent to:
[code=mysql]
CREATE TABLE table_name
(
id BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY auto_increment
)
[/code]Comment
Comment