Auto_ increment is used to increase by 1 while insert a new data to mysql table. The auto increment column must be defined as key.
You can add auto_increment while creating new table. The mysql query is:
You created a table in which the column with specific definitions in mysql. You created table column without auto increment. Then how can you add it to existing column in mysql. The following mysql query is used to add auto increment to existing column in mysql.
Now your structure look like this:
Then you'll get error like this:
So you should be add 'AUTO_INCREMENT' with 'PRIMARY KEY' in mysql table.
Related Post:
Create table with auto_increment in mysql:
You can add auto_increment while creating new table. The mysql query is:
CREATE TABLE table1
(No int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
Game_name varchar(15), Image varchar(15))
Now the table is created with auto increment.
Add auto_increment to existing column in mysql:
You created a table in which the column with specific definitions in mysql. You created table column without auto increment. Then how can you add it to existing column in mysql. The following mysql query is used to add auto increment to existing column in mysql.
Mysql Query:
Alter table table_name modify column_name datatype(length) AUTO_INCREMENT PRIMARY KEY
Now we are going to add auto increment to column 'No' in mysql table 'table1'. The mysql query is:
Alter table table1 modify No int(5) AUTO_INCREMENT PRIMARY KEY
Consider the example:
The structure of table1 in database new look like this:
The structure of table1 in database new look like this:
Now we are going to add auto increment to column 'No' in mysql table 'table1'. The mysql query is:
Now your structure look like this:
Now you can see the column name 'No' is auto increment. Suppose your mysql query like below:
Alter table table1 modify No int(5) AUTO_INCREMENT
Then you'll get error like this:
So you should be add 'AUTO_INCREMENT' with 'PRIMARY KEY' in mysql table.
Related Post:
Change column name in mysql
Change column size in mysql table
Delete column in mysql table
Add column after specific field in mysql table
Move columns in mysql table
Change column size in mysql table
Delete column in mysql table
Add column after specific field in mysql table
Move columns in mysql table
change column datatype in mysql
Change table name in mysql
Add primary key to existing column in mysql
how to add auto increment to existing column in mysql
How to remove auto increment from column in mysql
How to reset auto increment initial value in mysql
how to use order by before group by in mysqlChange table name in mysql
Add primary key to existing column in mysql
how to add auto increment to existing column in mysql
How to remove auto increment from column in mysql
How to reset auto increment initial value in mysql