MYSQL基础(DML)
来源:互联网 发布:在iphone编程 编辑:程序博客网 时间:2024/05/17 08:24
MySQL中(关键字),不区分大小写(数据区分大小写)。一般情况下,关键字全部大写。数据库表中每一行记录是唯一的(解决方法是定义主键)。
1 insert
insert into 表名(列名1, 列名2…列名n) values (值1,值2…值n);
注意:
值与列顺序相同,且值必须与对应的列的类型相同。
ex:insert into student(sno, name, age, gender, tel, score, birthday) values(1,’jack’,25,‘男’,‘110’, 80.5,’1990-1-1’);
如果没有全部列出所有列,其他没有对应的值的列,以null插入。
ex: insert into student(name, age,gender) values(‘jack’, 25, ‘男’);其他列对应的值为null.
如果表中所有列都要插入数据,可不用在表名后列出所有的列。以后插入数据,必须将列在表后显示出来。
ex: insert into student values(值1, 值2…值n);
2 Delete
Delete from 表格名 where condition;数据删除,可恢复,表结构不删除
Truncate 表格名; 数据删除,不可恢复, 表结构不删除,属于DDL语言
Drop table 表格名; 数据和表结构都删除,并且不可恢复
3 update
update 表名 set 列=值, 列=值…; 将某列的值修改成指定值
ex: 将stu表中age列的值修改成100,gender列值修改成女
update stu set age=100, gender=’女’;
update 表名 set 列=值,列=值… where condition(条件);
ex:将sal大于3000的工资增加500
update stu set sal=sal+500 where sal>3000;
ex:将年龄大于23的学生的工资增加300
update stu set sal=sal+300 where age > 23;
ex:将学号为1,11,21,31,41学生,年龄增长一岁,工资增长25%
update stu set age=age+sal=sal*1.25 where sno in (1, 11, 21, 31, 41);
1- 比较运算符
=、!=/<>、>、>=、<、<=
ex: 删除姓名为jack学生信息
delete from student where name=’jack’;
ex:删除性别不为女的所有学生信息
delete from student where gender != ‘女’;
ex:删除年龄大于25的所有学生信息
delete from student where age > 25;
2- and or
and连接两个条件,表示两个条件必须同时满足,结果才满足。
or 连接两个条件,表示其中任意一个条件成立,结果就成立。
ex:删除性别为男且年龄在25岁以上的所有学生信息
delete from student where gender=’男’ and age > 25;
ex:删除分数在80到90之间所有学生的信息
delete from student where score >= 80 and score <= 90;
ex:删除性别为男或者分数小于60分所有学生的信息
delete from student where gender=’男’ or score < 60;
ex:删除学号为1, 2, 3的学生信息
delete from student where sno = 1 or sno = 2 or sno = 3;
3- between min_val and max_val表示一段范围
ex:删除分数在80到90之间所有学生的信息
delete from student score between 80 and 90;
delete from student where score >= 80 and score <= 90;
4- in 表示离散的值
ex: 删除学号为1, 2, 3的学生信息
delete from student where sno = 1 or sno = 2 or sno = 3;
delete from student where sno in (1, 2, 3);
5- null
ex:删除电话为null的学生信息
delete from student where tel = null;
delete from student where tel is null;
6- not 表示取反
ex:删除分数不在80到90之间所有学生的信息
delete from student where score not between 80 and 90;
ex:删除学号不为1, 2, 3的所有学生信息
delete from student where sno not in (1, 2, 3);
ex:删除电话不为null的所有学生信息
delete from student where tel is not null;
- MYSQL基础(DML)
- MySQL基础 (DML)
- Mysql 基础DML语句
- MySQL基础-DML语句
- mysql 基础 ddl dml 总结
- MySQL-DML(二)
- MySQL基础语句值DML语句
- MySQL-基础-DDL、DML、DCL、TCL详解
- (mysql)DML语句 总结
- MySQL(八)之DML
- DML-MYSQL
- MYSQL DML
- Mysql总结2-mysql基础(DQL,DML,DDL,DCL)
- MySql(4)------SQL基础之DML(Data Manipulation Language)下的查询(select)语句
- php学习基础篇之mysql DDL DML 2
- MySQL 基础语句之 DML,DDL,DCL,TCL
- Oracle基础-UNION查询(DML)
- MySQL基本数据操作(DML)
- 语言控制台如何设置局部字体和背景的颜色
- 网易OpenStack部署运维实战
- 模仿微信,android bottom navigation的实现
- KVM虚拟化源码分析之KVM_TOOLS(一)
- 加载资源之路径问题
- MYSQL基础(DML)
- 网上找到的最简单说明建立IDoc的文章
- VPN
- Android软键盘的弹出和隐藏
- 9-5在类中定义装饰器
- 简述单例设计模式的一些理解及代码实现
- dataTables的属性及用法
- Java中hashcode方法与equals方法关联关系的直观解释
- 设计模式--23种模式精华(二)