CRUD操作 create创建 read读取 update修改 delete删除
1.注释语法:--,#
2.后缀是.sql的文件是数据库查询文件
3.保存查询
4.在数据库里面 列有个名字叫字段 行有个名字叫记录
CRUD操作:
create 创建(添加)
read 读取
update 修改
delete 删除
1、添加数据
insert into Info values('p009','张三',1,'n001','2016-8-30 12:9:8') ;
给特定的列添加数据
insert into Info (code,name) values('p010','李四');
自增长列的处理
insert into family values('','p001','数据','T001','数据',1);
insert into 表名 values(值)
2、删除数据
删除所有数据
delete from family
删除特定的数据
delete from Info where code='p001'
delete from 表名 where 条件
3、修改数据
修改所有数据
update Info set name='徐业鹏'
修改特定数据
update Info set name='吕永乐' where code='p002'
修改多列
update Info set name='吕永乐',sex=1 where code='p003'
update 表名 set 要修改的内容 where 条件
4、读取数据
(1)简单读取,查询所有列(*) 所有行(没有加条件)
select * from Info
(2)读取特定列
select code,name from Info
(3)条件查询
select * from Info where code='p003'
(4)多条件查询
select * from Info where code='p003' or nation='n002' #或的关系
select * from Info where sex=0 and nation='n002' #与的关系
(5)关键字查询(模糊查询)
查所有包含奥迪的汽车
select * from car where name like '%奥迪%'; #百分号%代表任意多个字符
查以'皇冠'开头的所有汽车
select * from car where name like '皇冠%';
查询汽车名称中第二个字符是'马'的
select * from car where name like '_马%'; #下划线_代表任意一个字符
(6)排序查询
select * from car order by powers #默认升序排列
select * from car order by powers desc #升序asc 降序 desc
先按brand升序排,再按照price降序排
select * from car order by brand,price desc
(7)范围查询
select * from car where price>40 and price<60
select * from car where price between 40 and 60
(8)离散查询
select * from car where price=30 or price=40 or price=50 or price=60;
select * from car where price in(30,40,50,60)
select * from car where price not in(30,40,50,60)
(9)聚合函数(统计查询)
select count(*) from car
select count(code) from car #取所有的数据条数
select sum(price) from car #求价格总和
select avg(price) from car #求价格的平均值
select max(price) from car #求最大值
select min(price) from car #求最小值
(10)分页查询
select * from car limit 0,10 #分页查询,跳过几条数据(0)取几条(10)
规定一个每页显示的条数:m
当前页数:n
select * from car limit (n-1)*m,m
(11)去重查询
select distinct brand from car
(12)分组查询
查询汽车表中,每个系列下汽车的数量
select brand,count(*) from car group by brand
分组之后,只能查询该列或聚合函数
取该系列价格平均值大于40的系列代号
select brand from car group by brand having avg(price)>40
取该系列油耗最大值大于8的系列代号
select brand from car group by brand having max(oil)>8
1.修改表的列
1.添加新列
alter table 表名 add 新列名 新列名类型
2.删除一列
alter table 表名 drop column 要删除的列名
3.修改表的列名
alter table car change name id varchar(20)
alter table 表名 change 列名 新列名 新列类型
CRUD操作 create创建 read读取 update修改 delete删除的更多相关文章
- 9.java 操作mongodb插入、读取、修改以及删除基础
1 package mongodb; import java.net.UnknownHostException; import java.util.ArrayList; import java.uti ...
- Cookie操作类、 包括创建、读取、修改、获取、销毁cookie
Cookie操作类. 包括创建.读取.修改.获取.销毁cookie import java.util.Hashtable; import java.util.Iterator; import java ...
- [转载]MongoDB学习 (四):创建、读取、更新、删除(CRUD)快速入门
本文介绍数据库的4个基本操作:创建.读取.更新和删除(CRUD). 接下来的数据库操作演示,我们使用MongoDB自带简洁但功能强大的JavaScript shell,MongoDB shell是一个 ...
- 在VC下采用ADO实现BLOB(Binary)数据的存储,读取,修改,删除。
在VC下采用ADO实现BLOB(Binary)数据的存储,读取,修改,删除. 作者:邵盛松 2009-09-05 前言 1关于的BLOB(Binary)数据的存储和读取功能主要参考了MSDN上的一篇& ...
- Oracle序列(Sequence)创建、使用、修改、删除
Oracle对象课程:序列(Sequence)创建.使用.修改.删除,序列(Sequence)是用来生成连续的整数数据的对象.序列常常用来作为主键中增长列,序列中的可以升序生成,也可以降序生成.创建序 ...
- ASP.NET 操作Cookie详解 增加,修改,删除
ASP.NET 操作Cookie详解 增加,修改,删除 Cookie,有时也用其复数形式Cookies,指某些网站为了辨别用户身份而储存在用户本地终端上的数据(通常经过加密).定义于RFC2109.它 ...
- 05Microsoft SQL Server 表创建,查看,修改及删除
Microsoft SQL Server 表创建,查看,修改及删除 创建表 创建普通表 use 数据库名称 go create table 表名称( 列1 ) not null, 列2 ) not n ...
- 网页中的数据的4个处理方式:CRUD(Creat, Retrive, Update, Delete)
网页中的数据的4个处理方式:CRUD(Creat, Retrive, Update, Delete) 2018-12-21, 后续完善
- js操作cookie(创建、读取、删除)方法总结
js操作cookie,可以通过开源的插件实现,方便快捷,兼容性好,同样也可以自己写: 此文主要介绍两个常用的插件: Js.cookie.js 和 jQuery.cookie.js 0.Js.cooki ...
随机推荐
- BZOJ3906 : Trie
将输入的Trie建成AC自动机,并建出fail树. 那么操作1等价于在给定点的子树的并集里都加1. 操作2等价于查询给定点到根节点路径的并集的权值和. 求出DFS序后,对于操作1,将点按进入时间戳从小 ...
- BZOJ3249 : [ioi2013]game
线段树套Treap 外层的线段树需要动态开节点 内层Treap需要注意的是,相同y坐标的点不一定是同一个点,所以需要再次离散 空间$O(n\log n)$ 时间$O(n\log^2n)$ #inclu ...
- Noi 2016
考砸只能说自己弱 Noi不是生活的全部, 人们也不会永远止步于失败. 大家加油 可以+我的qq:582744883
- 解决 PermGen space Tomcat内存设置
转自:http://qwzhl100.blog.163.com/blog/static/2133124200932813148637/ 在 使用Java程序从数据库中查询大量的数据或是应用服务器(如t ...
- post可以直接把get请求代入到目标url中
Feigong --非攻 非攻 取自<秦时明月>--非攻,针对不同情况自由变化的武器 Feigong,针对各种情况自由变化的mysql注入脚本 Feigong,In view of the ...
- Functional programming
In computer science, functional programming is a programming paradigm, a style of building the struc ...
- 【液晶模块系列基础视频】3.3fatfs接口函数的使用3
============================= 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:ht ...
- Maven 私有库 Nexus的安装
1.下载 Nexus下载地址:http://www.sonatype.org/nexus/go/ # wget https://sonatype-download.global.ssl.fastly. ...
- SonarQube代码质量管理平台安装与使用
Sonar简介 Sonar是一个用于代码质量管理的开源平台,用于管理源代码的质量,可以从七个维度检测代码质量 通过插件形式,可以支持包括java,C#,C/C++,PL/SQL,Cobol,JavaS ...
- jQuery前端验证多种方式
JQuery Validate使用总结:一.导入js库<script src="../js/jquery.js" type="text/javascript&quo ...