MYSQL REORDER PRIMARY KEY

MYSQL REORDER PRIMARY KEY

am 25.07.2007 15:44:01 von zach

Is there a way to sort all the data in my database such as alphabetical
or something, and then once sorted and have all the primary key's redone
according to the sorted order? I can sort them how I want, but I don't
know if there is a way to rename the primary id key on all the data once
sorted.

Thanks for any help.

zach

Re: MYSQL REORDER PRIMARY KEY

am 25.07.2007 15:52:02 von luiheidsgoeroe

On Wed, 25 Jul 2007 15:44:01 +0200, zach wrote:

> Is there a way to sort all the data in my database such as alphabetical
> or something, and then once sorted and have all the primary key's redone
> according to the sorted order? I can sort them how I want, but I don't
> know if there is a way to rename the primary id key on all the data once
> sorted.

I guess:
1. Add a field for new primary key.
2. Update using an order by close and a counter.
3. Drop primary key.
4. Create primary key on new field.
5. Possibly drop old field & rename new field. (ALTER TABLE tbl_name
CHANGE old_col_name column_definition )

However, unless your data is static, I'd think doing this is futile. Why
do you need it?
--
Rik Wasmus

Re: MYSQL REORDER PRIMARY KEY

am 25.07.2007 16:02:08 von Captain Paralytic

On 25 Jul, 14:44, zach wrote:
> Is there a way to sort all the data in my database such as alphabetical
> or something, and then once sorted and have all the primary key's redone
> according to the sorted order? I can sort them how I want, but I don't
> know if there is a way to rename the primary id key on all the data once
> sorted.
>
> Thanks for any help.
>
> zach

Why does it matter? Your primary key is a way to uniquely identify the
record. The database system can store them in any order it wants.
If the primary key for a row is FR67T before the table is sorted, then
it can still be the primary key after?
If you want a simple integer value primary key, then (depending on the
RDBMS you are using)you can use a counter to insert the records in a
new table with the required values or possibly use an auto-increment
column.

Re: MYSQL REORDER PRIMARY KEY

am 25.07.2007 16:05:12 von luiheidsgoeroe

On Wed, 25 Jul 2007 15:52:02 +0200, Rik wrote:
> 2. Update using an order by close and a counter.

*ahum*
2. Update using an order by clause and a counter.
--
Rik Wasmus