MySQLのデフォルト設定の追加・削除は以下のように行います。
デフォルト設定の追加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
mysql> show fields from site; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | NO | MUL | NULL | | | url | varchar(500) | NO | MUL | NULL | | | name | varchar(500) | NO | MUL | NULL | | | link_url | varchar(500) | NO | | NULL | | | category_id | int(11) | NO | MUL | NULL | | | description | text | NO | | NULL | | | published | int(11) | NO | | 0 | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 10 rows in set (0.02 sec) mysql> alter table site alter link_url set default 'http://example.com/'; Query OK, 0 rows affected (0.38 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show fields from site; +-------------+--------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | NO | MUL | NULL | | | url | varchar(500) | NO | MUL | NULL | | | name | varchar(500) | NO | MUL | NULL | | | link_url | varchar(500) | NO | | http://example.com/ | | | category_id | int(11) | NO | MUL | NULL | | | description | text | NO | | NULL | | | published | int(11) | NO | | 0 | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +-------------+--------------+------+-----+---------------------+----------------+ 10 rows in set (0.00 sec) |
デフォルト設定を削除
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
mysql> alter table site alter link_url drop default; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show fields from site; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | NO | MUL | NULL | | | url | varchar(500) | NO | MUL | NULL | | | name | varchar(500) | NO | MUL | NULL | | | link_url | varchar(500) | NO | | NULL | | | category_id | int(11) | NO | MUL | NULL | | | description | text | NO | | NULL | | | published | int(11) | NO | | 0 | | | created_at | datetime | NO | | NULL | | | updated_at | datetime | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 10 rows in set (0.04 sec) |
/