Created
October 31, 2013 16:20
-
-
Save lardcanoe/7252550 to your computer and use it in GitHub Desktop.
Convert action field to enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> create table test_enum (action varchar(255)); | |
Query OK, 0 rows affected (0.05 sec) | |
mysql> insert into test_enum set action="create"; | |
Query OK, 1 row affected (0.04 sec) | |
mysql> insert into test_enum set action="delete"; | |
Query OK, 1 row affected (0.00 sec) | |
mysql> insert into test_enum set action="update"; | |
Query OK, 1 row affected (0.00 sec) | |
mysql> alter table test_enum change action action enum("create", "delete", "update"); | |
Query OK, 3 rows affected (0.11 sec) | |
Records: 3 Duplicates: 0 Warnings: 0 | |
mysql> select * from test_enum; | |
+--------+ | |
| action | | |
+--------+ | |
| create | | |
| delete | | |
| update | | |
+--------+ | |
3 rows in set (0.04 sec) | |
mysql> insert into test_enum set action="delete"; | |
Query OK, 1 row affected (0.00 sec) | |
mysql> insert into test_enum set action=2; | |
Query OK, 1 row affected (0.00 sec) | |
mysql> select * from test_enum; | |
+--------+ | |
| action | | |
+--------+ | |
| create | | |
| delete | | |
| update | | |
| delete | | |
| delete | | |
+--------+ | |
5 rows in set (0.00 sec) | |
mysql> select * from information_schema.tables where TABLE_NAME="test_audit_records_enum"\G | |
*************************** 1. row *************************** | |
TABLE_CATALOG: def | |
TABLE_SCHEMA: cloudpercept | |
TABLE_NAME: test_audit_records_enum | |
TABLE_TYPE: BASE TABLE | |
ENGINE: InnoDB | |
VERSION: 10 | |
ROW_FORMAT: Compact | |
TABLE_ROWS: 1405719 | |
AVG_ROW_LENGTH: 148 | |
DATA_LENGTH: 208355328 | |
MAX_DATA_LENGTH: 0 | |
INDEX_LENGTH: 102957056 | |
DATA_FREE: 4194304 | |
AUTO_INCREMENT: 65415819 | |
CREATE_TIME: 2013-10-31 16:17:31 | |
UPDATE_TIME: NULL | |
CHECK_TIME: NULL | |
TABLE_COLLATION: latin1_swedish_ci | |
CHECKSUM: NULL | |
CREATE_OPTIONS: | |
TABLE_COMMENT: | |
1 row in set (0.06 sec) | |
mysql> select * from information_schema.tables where TABLE_NAME="audit_records"\G | |
*************************** 1. row *************************** | |
TABLE_CATALOG: def | |
TABLE_SCHEMA: cloudpercept | |
TABLE_NAME: audit_records | |
TABLE_TYPE: BASE TABLE | |
ENGINE: InnoDB | |
VERSION: 10 | |
ROW_FORMAT: Compact | |
TABLE_ROWS: 1460318 | |
AVG_ROW_LENGTH: 153 | |
DATA_LENGTH: 224100352 | |
MAX_DATA_LENGTH: 0 | |
INDEX_LENGTH: 169967616 | |
DATA_FREE: 416284672 | |
AUTO_INCREMENT: 65415935 | |
CREATE_TIME: 2013-09-18 15:32:35 | |
UPDATE_TIME: NULL | |
CHECK_TIME: NULL | |
TABLE_COLLATION: latin1_swedish_ci | |
CHECKSUM: NULL | |
CREATE_OPTIONS: | |
TABLE_COMMENT: | |
1 row in set (0.00 sec) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment