Title: RE: Changing column format

David,

I suggest that you don't. There are many "Jim Jones" in the world. How are you going to handle that? Is this field really your primary key and related to other tables or do you just need to make sure there are no duplicate names? If so, create a unique constraint instead.

If you must, first make sure that there is not already a duplicate name.

SELECT username, count(username)
FROM your_table_name
GROUP BY username
HAVING count(username) >1;

If you have any records returned, you need to fix your data before creating the primary key. Same thing with null values. If the SQL below returns a number other than zero, you need to put something in the null values before creating the primary key.

SELECT count(username)
FROM your_table_name
where username = Null;

To drop the primary key:

ALTER TABLE your_table_name
  DROP PRIMARY KEY CASCADE;

To create a primary key:

ALTER TABLE your_table_name
  ADD PRIMARY KEY (username);

Personally, I think you are going to regret doing this.

Jerry Whittle
ACIFICS DBA
NCI Information Systems Inc.
[EMAIL PROTECTED]
618-622-4145

    -----Original Message-----
    From:   Nguyen, David M [SMTP:[EMAIL PROTECTED]]

    I create a table to store user account information and set "userid" column
    to be primary key.  I now want to set "username" to be primary key instead
    of "userid", how do I change it?  There are couple hundreds of records in
    table.  Please advise.

    Thanks,
    David

Reply via email to