05表记录修改

05表记录的修改

1、修改记录基本语法

update 表名 set 字段名1=值1,字段名2=值2...,字段名n=值n [where 条件表达式]

2、删除表记录

  • delete from 表名 [where 条件表达式]

3、完全清空一个表

  • truncate [table] 表名

4、更新表记录

  • 删除字段:alter table 表名 drop 字段名

  • 修改表名:rename table 旧表名 to 新表名

  • 修改表名:alter table 旧表名 rename 新表名

  • 添加新的字段:alter table 表名 add 新字段名 新数据类型 [新约束条件] [first|after 旧字段名];

  • 修改表的字段名:alter table 表名 change 旧字段名 新字段名 新数据类型 ;

  • 仅对字段的数据类型进行修改:alter table 表名 modify 字段名 数据类型;

  • 添加约束条件:alter table 表名 add constraint 约束名 约束类型(字段名);

  • 删除表的主键约束:alter table 表名 drop primary key;

  • 删除表的外键约束:alter table 表名 drop foreign key 约束名;

  • 删除表字段的唯一约束:alter table 表名 drop index 唯一索引名

  • alter table 表名 engine = 新的存储引擎类型

  • alter table 表名 default charset = 新的字符集

  • alter table 表名 auto_increment = 新的初始值

注意:存在外键约束关系,若想删除父表,首先需要删除父表与子表之间的外键约束条件,解除“父子”,在删除表

猜你喜欢

转载自blog.csdn.net/weixin_42248871/article/details/109910502