List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 14 1999 3:00pm
Subject:Re: How make column UNIQUE NOT NULL AUTO_INCREMENT?
View as plain text  
>Ive been asking a lot of questions and I would
>like to say thanks a lot for all your responses.
>My first question is, how in Mysql do I make a column
>and at the same time add an index on it?
>I tried:
>CREATE TABLE table_name (
>	column_name int(255) UNIQUE NOT NULL AUTO_INCREMENT ,
>	KEY column_Inxname (column_name)
>Mysql does not like the UNIQUE in there.

That's because UNIQUE isn't a legal part of the CREATE TABLE syntax there.
It's as simple as that.  As has been pointed out in another posting, you
can use a PRIMARY KEY instead:

>CREATE TABLE table_name (
>    column_name int(255) NOT NULL AUTO_INCREMENT PRIMARY KEY

Note that a PRIMARY KEY is a UNIQUE index, so it may accomplish
what you want.

You could also name the UNIQUE key in a separate subclause if you

CREATE TABLE table_name (column_name int(255) NOT NULL AUTO_INCREMENT,
    UNIQUE (column_name)

Paul DuBois, paul@stripped
Northern League Chronicles:
How make column UNIQUE NOT NULL AUTO_INCREMENT?sam160014 Apr
  • Re: How make column UNIQUE NOT NULL AUTO_INCREMENT?Graham Ashton14 Apr
  • Re: How make column UNIQUE NOT NULL AUTO_INCREMENT?Paul DuBois14 Apr