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 显示不 ...
随机推荐
- 绿色版Tomcat 启动 + 停止 + 随系统自动启动 - - 博客频道 - CSDN.NET
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- java工程师联通XX面试题目
什么是“长连接”和“短连接”? 所谓短连接指建立SOCKET连接后发送后接收完数据后马上断开连接,一般银行都使用短连接解释2长连接就是指在基于tcp的通讯中,一直保持连接,不管当前是否发送或者接收数据 ...
- 检测网站挂马程序(Python)
系统管理员通常从svn/git中检索代码,部署站点后通常首先会生成该站点所有文件的MD5值,如果上线后网站页面内容被篡改(如挂马)等,可以比对之前生成MD5值快速查找去那些文件被更改,为了使系统管理员 ...
- WKWebKit基础
UIWebView & UIWebViewDelegate 这个两个东西在 WKWebKit 中被重构成 14 个类 3 个协议. WKWebKit Framework Classes WKB ...
- Extjs的架构设计思考,单页面应用 or 多页面?
写在前面:不要认为 EXTJS 高版本就是一个界面改良,在项目中,仍然用 N 张页面,在 N 张页面部署 EXTJS .这种方式不用多讲,效率问题大家都看得出来, EXTJS 是一个集成开发工具,注定 ...
- Java通过JNI调用dll详细过程(转)
源:Java通过JNI调用dll详细过程 最近项目有这样一个需求,在已有的CS软件中添加一个链接,将当前登录用户的用户名加密后放在url地址中,在BS的login方法里通过解密判断,如果为合法用户则无 ...
- 安卓组件service
[转]http://blog.csdn.net/ithomer/article/details/7364024 一. Service简介 Service是android 系统中的四大组件之一(Acti ...
- SQLite用法
SQLite语法:http://blog.csdn.net/ejzhang/article/details/6224915#08 SQLite查询优化:1.http://www.eoeandroid. ...
- OI队内测试一【数论概率期望】
版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] 测试分数:110 本应分数:160 改完分数:200 T1: 题 ...
- 【Xilinx-Petalinux学习】-03-PetaLinux通过eMMC方式启动
前面说的我的硬件上有一颗eMMC的芯片,型号是MTFC4GACAJCN-4M IT,有4GB的容量. BOOT.bin的文件较小,只有不到3MB,但是image.ub的文件根据不同的需求,将来可能会越 ...