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
thank you... It is useful
ReplyDeleteSometimes you should be careful with auto_increment. More info you can read here: Be Careful With MySQL's auto_increment. How We Ended Up Losing Data I leave it here and maybe it will be useful for some people. Cheers!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteMobile Robot Patents Transformative innovation is one which steadily expands upon the base progressive innovation. Yet, by it's very nature, the steady change is simpler for a contender to match or jump. Take for instance remote cellphone innovation. Organization V acquainted 4G items earlier with Company An and keeping in mind that it might have had a transient favorable position, when Company A presented their 4G items, the bit of leeway because of innovation vanished.
ReplyDelete