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 显示不 ...
随机推荐
- jquery.proxy的四种使用场景及疑问
作者:zccst 其实只有两种使用方式,只不过每一种又细分是否传参. 先给一段HTML,后面会用来测试: <p><button id="test">Test ...
- php的几个内置的函数
// 取得所有的后缀为PHP的文件 $files = glob(‘*.php’); print_r($files); j
- H3C inode for OSX 10.10 校园网客户端亲测可用
1.打开终端 2.输入以下命令 sudo /library/StartupItems/iNodeAuthService/iNodeAuthService start 3.输入管理密码 4.打开客户端联 ...
- [Unity Physics] Physics - Raycast
Class Variables类变量 gravity The gravity applied to all rigid bodies in the scene.场景中应用到所有刚性物体的重力. min ...
- RSA----实际函数库选择
需求:对字符串加密 加密后不要超过这个字符串的长度,最好是1半的长度. 非对称算法. 重复度一定要低 1使用RSA加密 1 rsaeuro 2openssl 参考openssl编程 3 Cr ...
- window.location.href 和 document.location.href
document表示的是一个文档对象,window表示的是一个窗口对象,一个窗口下可以有多个文档对象. 所以一个窗口下只有一个window.location.href,但是可能有多个document. ...
- eclipse注释模板设置(未整理)
Window --> Java --> Code Style --> Code Templates --> Comments --> types --> Edit ...
- nodejs抓取数据二(列表解析)
这里做得比较暴力,没有分页取出数据解析,O(∩_∩)O哈哈~,居然没有被挂机.不过解析的坑特别多...不过大部分我想要的数据都拿到了. //解析列表数据 var http = require(&quo ...
- iOS开发UITableView基本使用方法总结 分类: ios技术 2015-04-03 17:51 68人阅读 评论(0) 收藏
本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...
- nginx的一些配置
map $http_user_agent $***_build_version { default "***.exe"; "~Windows NT 10.0" ...