

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fix MySQL ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
To fix this error, you need to add PRIMARY KEY to auto_increment field. Let us now see how this error occurs −
Here, we are creating a table and it gives the same error −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT, StudentName varchar(40), StudentAge int ); ERROR 1075 (42000) : Incorrect table definition; there can be only one auto column and it must be defined as a key
To solve the above error, you need to add PRIMARY KEY with AUTO_INCREMENT. Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(40), StudentAge int ); Query OK, 0 rows affected (1.01 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(StudentName,StudentAge) values('Chris Brown',19); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable(StudentName,StudentAge) values('David Miller',18); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName,StudentAge) values('John Doe',20); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement :
mysql> select *from DemoTable;
This will produce the following output −
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 19 | | 2 | David Miller | 18 | | 3 | John Doe | 20 | +-----------+--------------+------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Fix ERROR 1064 (42000) while creating a database in MySQL?
- Fix for MySQL ERROR 1406: Data too long for column” but it shouldn't be?
- Can a number be used to name a MySQL table column?
- How many digits should be there in string or number so that it can be specified as a date value by MySQL?
- MySQL Error ERROR 1099 (HY000): Table was locked with a READ lock and can't be updated
- How to fix the incorrect datetime value while inserting in a MySQL table?
- What to assign to a MySQL column that must not be empty?
- Why the #1054 - Unknown column error occurs in MySQL and how to fix it?
- Fix Drop table view #1051 unknown table error in MySQL
- MySQL - How can I fix an auto increment field with deleted rows from 1,2,3,4,5 to 1,3,5). Now we want it to be 1,2,3
- How can we get the definition of a MySQL view as we can get the definition of a MySQL table?
- Fix Error in MySQL syntax while creating a table column with name “index”?
- How can column data values of a table be compared using MySQL STRCMP() function?
- Fix MySQL Database Error #1064?
- Fix Connectivity error in Java MySQL connection for connector to be set to class path?
Advertisements