From: Paul DuBois Date: April 14 1999 3:00pm Subject: Re: How make column UNIQUE NOT NULL AUTO_INCREMENT? List-Archive: http://lists.mysql.com/mysql/1828 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" >Hello, >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 >UNIQUE NOT NULL AUTO_INCREMENT >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 like: CREATE TABLE table_name (column_name int(255) NOT NULL AUTO_INCREMENT, UNIQUE (column_name) ) -- Paul DuBois, paul@stripped Northern League Chronicles: http://www.snake.net/nl/