Search code examples
mysqlprimary-keyauto-incrementalter-table

add primarykey with autoincrement in mysql


how to set particular column as primary key with auto increment in mysql.am using alter statement . but am getting error when i excecute the alter statement in mysql.

alter statement
---------------

 ALTER TABLE tbl_travelplan add COLUMN TRREQNO id INT(11) NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (id);    

Solution

  • I think the real problem is the space between TRREQNO and id in your query. Try the query i have placed below:

    ALTER TABLE tbl_travelplan add TRREQNO_id INT(11) NOT NULL primary KEY AUTO_INCREMENT;