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;

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值