473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to create a IDENTITY column in MySQL?

Please help me to create an IDENTITY column in MySQL
May 24 '07 #1
3 117336
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

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

Similar topics

3
by: Gunnar Vøyenli | last post by:
Hi (SQL Server 2000) I have an existing table (t) with a column that is NOT an identity column (t.ID), but it has manually inserted "row numbers". I want to make this column become an identity...
2
by: valerio | last post by:
Hi all, I've some problem to import data to DB2 using the db2move and db2look tools. Follow the problem : I have exported data from db2 v. 7 database on windows server, using the db2look and...
4
by: UDBDBA | last post by:
Hi: we have column with GENERATED ALWAYS AS DEFAULT. So, we can insert into this column manually and also let db2 generate a value for this column. Given a scenario, how can i find the NEXTVAL...
2
by: WhiteEagl | last post by:
Hello, I would need some help with this identity column problem in SQLServer. I have a database with two tables. The Parent table has an Identity column. Parent (ParentID IDENTITY, Name)...
2
by: Omavlana Omav | last post by:
Hi, I have created a datatable, dataadapter, added the table to a dataset and filling the table. Here I want to add an identity column to the above datatable and Later I will use this...
1
by: smauldin | last post by:
Creating a table with an identity column works fine create table test(a integer, id integer generated always as identity ) When I attempt to add an identity column it fails. create table...
8
by: shenanwei | last post by:
I have 2 same windows machine, same instance configure and Database , all run DB2 UDB V8.1.5 Test 1 : create table OUT_1 (LINE VARCHAR(350), LINENUMBER INTEGER NOT NULL GENERATED ALWAYS AS...
5
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as...
2
by: BobLewiston | last post by:
Most databases have multiple users. For these databases it is a good idea to auto-increment the identity column. I understand that the identity column is not incremented until the newly-created...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.