SQL CRUD 简单查询
identity 自增长
primary key 主键
unique 唯一键
not null 非空
references 外键(引用)
1.删除表
drop table Student
2.修改表
alter table RenYuan add CC int
alter table RenYuan drop column CC
3.删除数据库
drop database CeShi
CRUD操作
insert添加数据 read 读取数据 update 修改数据 delete 删除数据
1.添加数据
insert into Nation values('n002','回族')
insert into Nation values('n003','')
insert into Nation(code,name) values('n004','维吾尔族')
insert into Friends values('p001','p007')
2.删除数据
delete from Nation 删除所有
delete from Friends where ids = 5
3.修改数据
update Friends set fcode='p016' 修改所有
update Friends set fcode='p006',mcode='p002' where ids=4
查询:
1.简单查询
select * from Info --查所有数据
select Code,Name from Info --查指定列的数据
select Code as '代号',Name as '姓名' from Info --给列指定别名
2.条件查询
select * from Info where Code='p001'
select * from Info where Sex='true' and Nation='n001' --多条件并的关系
select * from Info where Sex='true' or Nation='n001' --多条件或的关系
3.范围查询
select * from Car where Price>40 and Price<50
select * from Car where Price between 40 and 50
4.离散查询
select * from Car where Code in ('c001','c005','c010','c015')
select * from Car where Code not in ('c001','c005','c010','c015')
5.模糊查询
select * from Car where Name like '%宝马%' --查包含宝马的
select * from Car where Name like '宝马%' --查以宝马开头的
select * from Car where Name like '%宝马' --查以宝马结尾的
select * from Car where Name like '宝马' --查等于宝马的
select * from Car where Name like '__E%' --查第三个字符是E的
% 代表是任意多个字符
_ 代表是一个字符
6.排序查询
select * from Car order by Price asc --以价格升序排列
select * from Car order by Price desc --以价格降序排列
select * from Car order by Oil desc,Price asc --以两个字段排序,前面的是主条件后面的是次要条件
7.分页查询
select top 5 * from Car
select top 5 * from Car where Code not in (select top 5 Code from Car)
当前页:page = 2; 每页显示:row = 10;
select top row * from Car where Code not in (select top (page-1)*row Code from Car)
8.去重查询
select distinct Brand from Car
9.分组查询
select Brand from Car group by Brand having count(*)>2
10.聚合函数(统计查询)
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 --求最小值
SQL CRUD 简单查询的更多相关文章
- Oracle之SQL的简单查询
查询结构 --SQL语句的执行原理以及语法结构: /* SELECT * | 列名1[,列名2...] | 表达式 FROM 表名 [表的别名] WHERE 分组前的筛选条件 GROUP BY 列名1 ...
- mysql,Jdbc工具类,只需一条sql实现简单查询
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import ...
- Sql Server 简单查询 异步服务器更新语句
//结构:select 子句 [into 子句] from 子句 [where 子句] [group by 子句] [having 子句] [order by 子句] select dept_c ...
- CRUD简单查询
一.查询所有数据 select * from car 二.查询指定列 select code , price from car 三.修改查询出的列名 select code as '代号' , nam ...
- LINQ to Sql系列二 简单查询和联接查询
这一篇文章主要总结LINQ to sql的简单查询(单表查询)和联接查询(多表查询) 单表查询 需求是我们要输出TClass表中的结果.使用了from-in-select语句,代码如下: public ...
- SQL Server温故系列(2):SQL 数据操作 CRUD 之简单查询
1.查询语句 SELECT 1.1.查询语句的 SELECT 子句 1.2.查询语句的 FROM 子句 1.2.1.内连接查询 INNER JOIN 1.2.2.外连接查询 OUTER JOIN 1. ...
- SQL server 数据库 操作及简单查询
使用SQL Sever语言进行数据库的操作 常用关键字identity 自增长primary key 主键unique 唯一键not null 非空references 外键(引用) 在使用查询操作数 ...
- 010.简单查询、分组统计查询、多表连接查询(sql实例)
-------------------------------------day3------------ --添加多行数据:------INSERT [INTO] 表名 [(列的列表)] --SEL ...
- 学习笔记:oracle学习三:SQL语言基础之检索数据:简单查询、筛选查询
目录 1. 检索数据 1.1 简单查询 1.1.1 检索所有列 1.1.2 检索指定的列 1.1.3 查询日期列 1.1.4 带有表达式的select语句 1.1.5 为列指定别名 1.1.6 显示不 ...
随机推荐
- head和tail命令-----得到头尾N行或者这去掉尾头N/N-1行
[algo@localhost tmp]$ cat test 1 2 3 4 5 head得到头部2行,删掉尾部2行 [algo@localhost tmp]$ head -n +2 test 1 ...
- 基于LNMP的Zabbbix之Zabbix Server源码详细安装,但不给图
Zabbix Server安装 看到那里有错或者有什么问题的话,求指点 邮箱:losbyday@163.com 上一篇PHP源码安装参见基于LNMP的Zabbbix之PHP源码安装:https://i ...
- angular中的$http配置和参数
依赖:$httpBackend $cacheFactory $rootScope $q $injector 使用:$http(config); 参数: method:字符串,请求方法. url:字符串 ...
- Adaptive Server Enterprise ODBC driver connection strings
Adaptive Server Enterprise 15.0 Driver={Adaptive Server Enterprise};app=myAppName;server=myServerAdd ...
- RoundedImageView使用吐槽心得(RoundedImageView与Glide加载图片,第一次加载无法圆角问题)
最近使用的时候发现一个问题, RoundedImageView与Glide搭配使用的时候,第一次加载图片(内存中没有),后图片无法圆角,后来尝试各种改,最后想到了一个办法,就是让Glide加载图片的 ...
- MongoDB的$type操作符
字段类型定义: db.col.find({"title" : {$type : 2}})
- 安卓selector
定义styles.xml <?xml version="1.0" encoding="utf-8"?> <resources> < ...
- 4.ICMP协议,ping和Traceroute
1.IMCP协议介绍 前面讲到了,IP协议并不是一个可靠的协议,它不保证数据被送达,那么,自然的,保证数据送达的工作应该由其他的模块来完成.其中一个重要的模块就是ICMP(网络控制报文)协议. 当传送 ...
- jquery 中prop()的使用方法
1:设置input的选中属性:$('.passenger').find('.is-need-tel').prop('checked',true); 2:获取input是否选中: $('.passeng ...
- codeforces 755C. PolandBall and Forest
C. PolandBall and Forest time limit per test 1 second memory limit per test 256 megabytes input stan ...