MySQL操作程序三十七(makers table增加 nation)

返回


mysql> ALTER TABLE makers ADD nationid INT NOT NULL DEFAULT 2;==>OK Query OK, 749 rows affected (0.22 sec) Records: 749 Duplicates: 0 Warnings: 0 ALTER TABLE makers ADD nationid INT SET DEFAULT 2;==>NG ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET D EFAULT 2' at line 1 ALTER TABLE makers DROP nationid; ALTER TABLE makers ALTER nationid SET DEFAULT 2;==>没有改变 mysql> insert into makers (nationid) values("2");==>只插入了一个! Query OK, 1 row affected (0.08 sec) mysql> show columns from makers; +----------+-----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | company | char(100) | YES | | NULL | | | address | char(100) | YES | | NULL | | | person | char(50) | YES | | NULL | | | telfax | char(100) | YES | | NULL | | | email | char(100) | YES | | NULL | | | homepage | char(100) | YES | | NULL | | | memo | char(200) | YES | | NULL | | | nationid | int(11) | YES | | NULL | | +----------+-----------+------+-----+---------+----------------+ 9 rows in set (0.02 sec) ALTER TABLE makers ADD nationid INT AFTER memo; mysql> show columns from makers; +----------+-----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | company | char(100) | YES | | NULL | | | address | char(100) | YES | | NULL | | | person | char(50) | YES | | NULL | | | telfax | char(100) | YES | | NULL | | | email | char(100) | YES | | NULL | | | homepage | char(100) | YES | | NULL | | | memo | char(200) | YES | | NULL | | +----------+-----------+------+-----+---------+----------------+ 8 rows in set (0.24 sec)
返回