Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Mysql-alter Mysql Alter Table Identity

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql Alter Table Identity

Advertisement
Mysql Alter Table Identity is used to change the existing structure of table and add ID column as identity key that is used to uniquely define the records in the table.

Mysql Alter Table Identity

     

Mysql Alter Table Identity is used to change the existing structure of table and add ID column as identity key that is used to uniquely define the records in the table.

Understand with Example

The Tutorial illustrate an example from 'Mysql Alter Table Identity'. To understand and elaborate an example, we create a table "userform" with required fieldnames and datatypes respectively.

Create table "userform" : 

      +----------+--------------+------+-----+---------+-------+
      | Field    | Type         | Null | Key | Default | Extra |
      +----------+--------------+------+-----+---------+-------+
      | username | varchar(100) | YES  |     |         |       |
      | fname    | varchar(100) | YES  |     |         |       |
      | email    | varchar(100) | YES  |     |         |       |
      | count    | bigint(20)   | YES  |     | 100     |       |

The Alter Table modifies the table 'userform 'and add ID as Primary Key  that uniquely identifies the records in the table.

ALTER TABLE userform ADD ID INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (ID);

After alter the table "userform"

      +----------+--------------+------+-----+---------+----------------+
      | Field    | Type         | Null | Key | Default | Extra          |
      +----------+--------------+------+-----+---------+----------------+
      | ID       | int(11)      | NO   | PRI |         | auto_increment |
      | username | varchar(100) | YES  |     |         |                |
      | fname    | varchar(100) | YES  |     |         |                |
      | email    | varchar(100) | YES  |     |         |                |
      | count    | bigint(20)   | YES  |     | 100     |                |
  
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 16, 2009

Related Tutorials

Discuss: Mysql Alter Table Identity  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com