
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- 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?
- Fix Error in MySQL syntax while creating a table column with name “index”?
- Why the #1054 - Unknown column error occurs in MySQL and how to fix it?
- Can a number be used to name a MySQL table column?
- MySQL Error ERROR 1099 (HY000): Table was locked with a READ lock and can't be updated
- Match column I with column II. There can be more than one match.
- Fix Drop table view #1051 unknown table error in MySQL
- How many digits should be there in string or number so that it can be specified as a date value by 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 to fix the incorrect datetime value while inserting in a MySQL table?
- How can we get the definition of a MySQL view as we can get the definition of a MySQL table?
- What to assign to a MySQL column that must not be empty?
- Fix MySQL Database Error #1064?
- How to make MySQL table primary key auto increment?

Advertisements