Chiubaka
Chiubaka

Reputation: 789

Altering Table Information in MySQL

I'm relatively new to MySQL.

So, let's say I make a table and my table utilizes an "id" column to keep track of a unique identification number. However, when creating my table, I neglected to specify that I wanted the column to be auto-incremented, not null, and the primary key of the table. What MySQL statement can I use to alter the information of this table so that it is correct for what I want? I have tried some variations of the "ALTER TABLE" command, don't seem to understand the syntax.

Upvotes: 0

Views: 140

Answers (2)

Imre L
Imre L

Reputation: 6249

ALTER TABLE `yourTable`
    CHANGE COLUMN `id` `id` INT(10) NOT NULL AUTO_INCREMENT FIRST,
    ADD PRIMARY KEY (`id`);

Upvotes: 0

ArtoAle
ArtoAle

Reputation: 2977

use this:

ALTER TABLE `table_name` 
MODIFY COLUMN `id` BIGINT( 20 )  PRIMARY KEY AUTO_INCREMENT

Upvotes: 1

Related Questions