List:General Discussion« Previous MessageNext Message »
From:Graham Ashton Date:April 14 1999 6:59am
Subject:Re: How make column UNIQUE NOT NULL AUTO_INCREMENT?
View as plain text  
On Wednesday 14 April, sam1600@stripped wrote:

> 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 do this;

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

I think you need a column to be a primary key in order for auto_increment to
work. You can specify other unique relationships later. e.g.

CREATE TABLE table_name (
    column_name INT(255) NOT NULL AUTO_INCREMENT PRIMARY KEY
    second_column INT NOT NULL,
    third_column VARCHAR(40) NOT NULL,
    UNIQUE (second_column, third_column)
);

> If I take the UNIQUE out of the declaration it works
> but -phpMyAdmin- reports the Column and it's key as
> NOT UNIQUE

I think the command line mysql client says that it needs to be the
primary key, not just unique.

There'll be better ways of doing this, but I guess it's a start.

-- 
Graham
Thread
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