Mysql Alter Table Identity

Ads
 

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.

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     |                |
  

Ads

Ads