* Rhino:
> You'll need three alter statements:
> - one to add the new column
> - one to get rid of the old primary key
> - one to set the new column as the primary key

In addition to adding the new column, there will be neccessary to populate
the column with unique values. A primary key must allways contain unique
values.

> Something like this, i.e. I've left out some details of the syntax:
> ALTER TABLE FOO ADD USERID CHAR(8);
> ALTER TABLE FOO DROP PRIMARY KEY;
> ALTER TABLE FOO ADD PRIMARY KEY(USERID);
>
> Your basic mistake is that you're trying to make all the changes in one
> statement; SQL pretty much forces you to change each aspect of the table
> in a separate ALTER TABLE statement.

This is not correct, you can have multiple changes in the same ALTER TABLE
statement, for instance:

ALTER TABLE FOO
  ADD USERID CHAR(8) NOT NULL,
  DROP PRIMARY KEY,
  ADD PRIMARY KEY(USERID);

This would only work on an empty or a single-row table, or you would get
duplicate key errors.

-- 
Roger


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to