MYSQL_数据操纵语言DML

数据操纵语言DML:

插入数据: insert

格式:
默认式插入:插入的数据的类型必须与表的字段类型一一对应;

insert into tableName values(col1, col2, …);

对应字段式插入:插入的数据类型与tableName 后的”()”中的字段类型相匹配,相对于默认式插入方法要更加清楚明了,也不容易出错;

insert into tableName (colName1, colName2, …)
values(col1, col2, …);

--创建一个teacher表,字段有tid int(4),tname char(10),tage int(2),tbirth date
create table teacher(
tid int(4),
tname char(10),
tage int(2),
tbirth date
);
--分别使用两种插入的方式插入两行记录(数据)
insert teacher values(1001,'高圆圆',38,'1983-10-12');
insert teacher (tid,tname,tage)
value(1002, '夜华', 40);

这里写图片描述

删除数据: delete

格式:

delete from tableName [where <条件表达式>];
若没有条件表达式,删除表内所有记录

--删除tid为1002的所有记录(数据)
delete from teacher
where tid = 1002; 

这里写图片描述

修改数据: updata

格式:

updata tableNmae set colName1 = value1 [, colName2 = value2, …] [where…];
若没有where,修改表内所有该字段的数据

--修改表中tid为1001的tname为林俊杰;
update teacher 
set tname = '林俊杰'
where tid = 1001;

这里写图片描述

猜你喜欢

转载自blog.csdn.net/yc_hen/article/details/82466891