php - change all id to uuid -
i designed mysql table id primary key. table populated data. now, change id column uuid , change populated data's id fields uuid. i'm thinking of doing php. there alternatives?
have @ below demo, have table city following structure , need add uuid column in it
mysql> show create table city\g *************************** 1. row *************************** table: city create table: create table `city` ( `id` int(11) not null auto_increment, `name` char(35) not null default '', `countrycode` char(3) not null default '', `district` char(20) not null default '', `population` int(11) not null default '0', primary key (`id`) ) engine=innodb auto_increment=4080 default charset=latin1 1 row in set (0.00 sec) id primary key in table, check data
mysql> select * city limit 10; +----+----------------+-------------+---------------+------------+ | id | name | countrycode | district | population | +----+----------------+-------------+---------------+------------+ | 1 | kabul | afg | kabol | 1780000 | | 2 | qandahar | afg | qandahar | 237500 | | 3 | herat | afg | herat | 186800 | | 4 | mazar-e-sharif | afg | balkh | 127800 | | 5 | amsterdam | nld | noord-holland | 731200 | | 6 | rotterdam | nld | zuid-holland | 593321 | | 7 | haag | nld | zuid-holland | 440900 | | 8 | utrecht | nld | utrecht | 234323 | | 9 | eindhoven | nld | noord-brabant | 201843 | | 10 | tilburg | nld | noord-brabant | 193238 | +----+----------------+-------------+---------------+------------+ 10 rows in set (0.00 sec) add column uuid values
mysql> alter table city add column uuid_id char(36); query ok, 4079 rows affected (1.70 sec) records: 4079 duplicates: 0 warnings: 0 check data , shows null in uuid_id column
mysql> select * city limit 10; +----+----------------+-------------+---------------+------------+---------+ | id | name | countrycode | district | population | uuid_id | +----+----------------+-------------+---------------+------------+---------+ | 1 | kabul | afg | kabol | 1780000 | null | | 2 | qandahar | afg | qandahar | 237500 | null | | 3 | herat | afg | herat | 186800 | null | | 4 | mazar-e-sharif | afg | balkh | 127800 | null | | 5 | amsterdam | nld | noord-holland | 731200 | null | | 6 | rotterdam | nld | zuid-holland | 593321 | null | | 7 | haag | nld | zuid-holland | 440900 | null | | 8 | utrecht | nld | utrecht | 234323 | null | | 9 | eindhoven | nld | noord-brabant | 201843 | null | | 10 | tilburg | nld | noord-brabant | 193238 | null | +----+----------------+-------------+---------------+------------+---------+ 10 rows in set (0.00 sec) update table uuid() values
mysql> update city set uuid_id = uuid(); query ok, 4079 rows affected (1.34 sec) rows matched: 4079 changed: 4079 warnings: 0 check data again, table contains values column uuid_id
mysql> select * city limit 10; +----+----------------+-------------+---------------+------------+--------------------------------------+ | id | name | countrycode | district | population | uuid_id | +----+----------------+-------------+---------------+------------+--------------------------------------+ | 1 | kabul | afg | kabol | 1780000 | 91301a65-a91a-11e3-b0c9-001cc0e52f34 | | 2 | qandahar | afg | qandahar | 237500 | 9131afaf-a91a-11e3-b0c9-001cc0e52f34 | | 3 | herat | afg | herat | 186800 | 9131b1f8-a91a-11e3-b0c9-001cc0e52f34 | | 4 | mazar-e-sharif | afg | balkh | 127800 | 9131b37b-a91a-11e3-b0c9-001cc0e52f34 | | 5 | amsterdam | nld | noord-holland | 731200 | 9131b4f8-a91a-11e3-b0c9-001cc0e52f34 | | 6 | rotterdam | nld | zuid-holland | 593321 | 9131b65f-a91a-11e3-b0c9-001cc0e52f34 | | 7 | haag | nld | zuid-holland | 440900 | 9131b7cb-a91a-11e3-b0c9-001cc0e52f34 | | 8 | utrecht | nld | utrecht | 234323 | 9131b92d-a91a-11e3-b0c9-001cc0e52f34 | | 9 | eindhoven | nld | noord-brabant | 201843 | 9131ba88-a91a-11e3-b0c9-001cc0e52f34 | | 10 | tilburg | nld | noord-brabant | 193238 | 9131bfdd-a91a-11e3-b0c9-001cc0e52f34 | +----+----------------+-------------+---------------+------------+--------------------------------------+ 10 rows in set (0.00 sec) now can drop id column , rename uuid_id id
Comments
Post a Comment