16:18>alter table A add phone varchar(20); Query OK, 0 rows affected (0.13 sec) v 增加有完整约束条件的字段: root@zytest 16:42>alter table A add age int(4) not null; Query OK, 0 rows affected (0.13 sec) v 在表的第一个位置增加字段默认情况每次增加的字段。都在表的最后。 root@zytest 16:45>alter table tt add num int(8) primary key first; Query OK, 1 row affected (0.12 sec) Records: 1 Duplicates: 0 Warnings: 0 v 执行在那个位置插入新的字段,在phone后面增加 root@zytest 16:46>alter table A add address varchar(30) not null after phone; Query OK, 0 rows affected (0.10 sec) Records: 0 Duplicates: 0 Warnings: 0 总结: (1) 默认ADD 增加字段是在最后面增加 (2) 如果想在表的最前端增加字段用first关键字 (3) 如果想在某一个字段后面增加的新的字段,使用after关键字 5>删除一个字段 alter table 表名DROP 属性名; 举例: 删除A 表的age字段 root@zytest 16:51>alter table A drop age; Query OK, 0 rows affected (0.11 sec) Records: 0 Duplicates: 0 Warnings: 0 6>更改表的存储引擎 alter table表名 engine=存储引擎 alter table A engine=MyISAM; 7>删除表的外键约束 alter table 表名drop foreign key 外键别名; alter table yy2 drop foreign key y_fk;
4》删除表的方法
1>删除没有被关联的普通表 drop table 表名; 2>删除被其它表关联的父表 在数据库中某些表之间建立了一些关联关系。一些成为了父表,被其子表关联,要删除这些父表,就不是那么简单了。删除方法,先删除所关联的 子表的外键,在删除主表。
|