mysql中的update(更新)与alter(更改)以及change和modify 的区别
Mysql中 update、alter 以及 change 和 modify 的区别
·
- update(更新)与alter(更改)
- update更新的是数据值,alter更改的是数据库、表的结构(增加⾏或者减少⾏,增加列或者
减少类等等情况,还有修改字段(属性)类型)
举例:
(1)alter:
– #SC 主键组合
– alter table SC add primary key(Sno,Cno);
– #3,在Student表中添加⼀列名为dept,类型为char(50),允许为空的列:
– alter table Student add columnSdeptchar(50);
– #4,将Course表的Ccredit 类型改为 double
– alter table Course modify columnCcreditdouble;
等等。。。
(2)update:
– #修改学⽣201215121 的年龄为22岁
– update Student setSage=22 whereSno=‘201215121’;
- change和modify
change改变字段名和字段类型;modify 字段的类型;即,change字段名、字段类型都可以改
变,⽽modify只能改改字段类型。change的功能更加强⼤。
举例:
(1)modify:
– #4,将Course表的Ccredit 类型改为 double
– alter table Course modify columnCcreditdouble;
(2)change:
假设表中columnCcredit的类型是char(50);
– alter table Course change columnCcreditcredit char(10); ~既改名⼜改类型
– alter table Course change columnCcreditcredit char(50); ~只改名
– alter table Course change columnCcreditCcreditchar(50); ~只改类型
更多推荐



所有评论(0)