How do I create a MySQL table with an auto increment field?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

How do I create a MySQL table with an auto increment field?

Postby PapaGeek » 30. November 2017 05:50

I downloaded and installed XAMPP 7.1.11 and I am trying to create a table with an auto increment key.

Database test1, table Users, fields xxx and Name.

Using XAMPP Control Panel v3.2.2: I start Apache and MySQL, then I click on Admin on the MySQL line and get the phpMyAdmin page.

Click on Databases, enter test1 in the Create database field, leave the dropdown as “Collation” and click on Create.

The database is created and I enter “Users” in the Create table name field and change the number of columns to 2, then I click “Go”.

I enter “xxx” in the first name field, leave type as INT, set Length to 10, leave default as None and click the A…I box.

When I do that a form pops up labeled Add index, and I cancel out of it. I have tried all different ways of handling that pop up menu, nothing works!

I fill in the second field as Name, Varchar 50.

The preview SQL gives me:
Code: Select all
CREATE TABLE `test1`.`Users` ( `xxx` INT(10) NOT NULL AUTO_INCREMENT , `Name` VARCHAR(50) NOT NULL ) ENGINE = InnoDB;


Then I hit the save button and get the pop up message:

Code: Select all
#1075: Incorrent table definition, there can be only one auto column and it must be defined as a key.


The dropdown for Type for each column does not include “key”. How do I create a table with an auto increment key?
PapaGeek
 
Posts: 2
Joined: 24. November 2017 08:38
XAMPP version: 7.1.11
Operating System: Windows 7

Re: How do I create a MySQL table with an auto increment fie

Postby Nobbie » 30. November 2017 11:38

PapaGeek wrote:When I do that a form pops up labeled Add index


Exactly, as AUTO_INCREMENT is an attribute of the PRIMARY Key and nothing else.

PapaGeek wrote:and I cancel out of it.


Why?? You *should* apply "PRIMARY" here, as you want AUTO_INCREMENT.

PapaGeek wrote:I have tried all different ways of handling that pop up menu, nothing works!


Of course not, if you activate AUTO_INCREMENT, you automatically MUST define this as key.

PapaGeek wrote:The dropdown for Type for each column does not include “key”.


Of course not, "key" is NOT a datatype (types are "CHAR" or "INT" etc.), the key is a so called "Index" and therefore the Index Box pops up to force you to apply a proper index / key.

PapaGeek wrote:How do I create a table with an auto increment key?


Without any? SImply dont activate A...I for any field. But a table without any key is stupid (sorry, but SQL without keys is like a knife without a blade missing the handle).
Nobbie
 
Posts: 13182
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 144 guests