Add Auto-Increment ID to existing table

0 votes

I already have a database with the columns "fname," "lname," "email," "password," and "ip." I now, however, desire an auto-increment column. Nevertheless, as I enter:

ALTER TABLE users
ADD id int NOT NULL AUTO_INCREMENT

I get the following:

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

Can someone please help me with this?

Sep 8, 2022 in Database by Kithuzzz
• 38,020 points
1,320 views

1 answer to this question.

0 votes

Try this

ALTER TABLE `users` ADD `id` INT NOT NULL AUTO_INCREMENT;

I hope this helps you.

answered Sep 10, 2022 by narikkadan
• 63,680 points

Related Questions In Database

0 votes
0 answers

Add Foreign Key to existing table

I want to add a Foreign Key ...READ MORE

Sep 3, 2022 in Database by Kithuzzz
• 38,020 points
617 views
0 votes
1 answer

Do I need to add primary key in each and every table?

Hi Shraddha, You have a doubt to add ...READ MORE

answered May 29, 2019 in Database by sampriti
• 1,120 points
1,464 views
0 votes
1 answer

How to generate the statement CREATE TABLE for an existing table in postgreSQL?

Generate table creation statement for an existing ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,020 points
6,566 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to change the default value and to alter a column in sql?

Hi, You can try this: ALTER TABLE foobar_data CHANGE ...READ MORE

answered Jun 24, 2019 in Big Data Hadoop by Gitika
• 65,890 points
1,501 views
0 votes
1 answer

What is an index in SQL?

An index is used to speed up ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
651 views
0 votes
1 answer

Ordering by the order of values in a SQL IN() clause

Use MySQL's FIELD() function: SELECT name, description, ... FROM ... WHERE id ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,020 points
5,214 views
0 votes
1 answer

Add primary key to existing table

You have to drop constraint and recreate ...READ MORE

answered Sep 12, 2022 in Database by narikkadan
• 63,680 points
555 views
0 votes
1 answer

Add a column with a default value to an existing table in SQL Server

Syntax: ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT ...READ MORE

answered Sep 12, 2022 in Database by narikkadan
• 63,680 points
2,441 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP