mysql> create table payment_log(id int auto_increment primary key, user_id int, created_time datetime, value int, detail varchar(200), index idx_user(user_id), index idx_time(created_time));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into payment_log set id=null, user_id=1, created_time=now(), value=5000000, detail='Mua sex toy de ban';
Query OK, 1 row affected (0.00 sec)
mysql> insert into payment_log set user_id=1, created_time='2011-01-01 00:00:00', value=500000, detail='Mua cay canh';
Query OK, 1 row affected (0.00 sec)
mysql> select * from payment_log;
+----+---------+---------------------+---------+--------------------+
| id | user_id | created_time | value | detail |
+----+---------+---------------------+---------+--------------------+
| 1 | 1 | 2010-05-20 15:17:02 | 5000000 | Mua sex toy de ban |
| 2 | 1 | 2011-01-01 00:00:00 | 500000 | Mua cay canh |
+----+---------+---------------------+---------+--------------------+
2 rows in set (0.00 sec)
mysql> alter table payment_log drop column id;
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from payment_log;
+---------+---------------------+---------+--------------------+
| user_id | created_time | value | detail |
+---------+---------------------+---------+--------------------+
| 1 | 2010-05-20 15:17:02 | 5000000 | Mua sex toy de ban |
| 1 | 2011-01-01 00:00:00 | 500000 | Mua cay canh |
+---------+---------------------+---------+--------------------+
2 rows in set (0.00 sec)
mysql> alter table payment_log add column id int auto_increment first, add primary key(id);
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from payment_log;
+----+---------+---------------------+---------+--------------------+
| id | user_id | created_time | value | detail |
+----+---------+---------------------+---------+--------------------+
| 1 | 1 | 2010-05-20 15:17:02 | 5000000 | Mua sex toy de ban |
| 2 | 1 | 2011-01-01 00:00:00 | 500000 | Mua cay canh |
+----+---------+---------------------+---------+--------------------+
2 rows in set (0.00 sec)
mysql> notee
Title:
Add, remove column id int auto_increment primary key
Description:
mysql> create table payment_log(id int auto_increment primary key, user_id int, created_time datetime, value int, detail varchar(200), in...
...
Rating:
4