添加字段
alert table 表名 add 字段名 类型(长度) comment '注释',
示例:
alter table student add power varchar(50) comment '注释';
修改字段
*仅修改字段的数据类型
alter table 表名 modify 字段名 新的数据类型(长度)
同时修改字段名和字段类型
alter table 表名 change 旧的字段 新的字段 新的数据类型(长度) comment '注释';
删除
alter table 表名 drop 字段名;
示例:
alter table student drop power;
修改表的名称
alter table 表名 rename to 新的表名;
示例:
alter table student rename to stu;
删除表
drop table if exists 表名;
if exists指“如果表存在”,可以不加。
删除表,并创建这张表(名称与之前相同)
truncate table 表名;
示例:
create table text3(id int(3));
(先创建一个text3的表,然后将其删除)
truncate table text3;
修改数据
update 表名 set 列1=值1,列2=值2,where id=1;
示例:
update student set class=17,power=1 where id=2;
评论 (0)