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 简单查询的更多相关文章

  1. Oracle之SQL的简单查询

    查询结构 --SQL语句的执行原理以及语法结构: /* SELECT * | 列名1[,列名2...] | 表达式 FROM 表名 [表的别名] WHERE 分组前的筛选条件 GROUP BY 列名1 ...

  2. mysql,Jdbc工具类,只需一条sql实现简单查询

    import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import ...

  3. Sql Server 简单查询 异步服务器更新语句

    //结构:select 子句 [into 子句] from 子句  [where 子句] [group by 子句]  [having 子句] [order by 子句] select  dept_c ...

  4. CRUD简单查询

    一.查询所有数据 select * from car 二.查询指定列 select code , price from car 三.修改查询出的列名 select code as '代号' , nam ...

  5. LINQ to Sql系列二 简单查询和联接查询

    这一篇文章主要总结LINQ to sql的简单查询(单表查询)和联接查询(多表查询) 单表查询 需求是我们要输出TClass表中的结果.使用了from-in-select语句,代码如下: public ...

  6. SQL Server温故系列(2):SQL 数据操作 CRUD 之简单查询

    1.查询语句 SELECT 1.1.查询语句的 SELECT 子句 1.2.查询语句的 FROM 子句 1.2.1.内连接查询 INNER JOIN 1.2.2.外连接查询 OUTER JOIN 1. ...

  7. SQL server 数据库 操作及简单查询

    使用SQL Sever语言进行数据库的操作 常用关键字identity 自增长primary key 主键unique 唯一键not null 非空references 外键(引用) 在使用查询操作数 ...

  8. 010.简单查询、分组统计查询、多表连接查询(sql实例)

    -------------------------------------day3------------ --添加多行数据:------INSERT [INTO] 表名 [(列的列表)] --SEL ...

  9. 学习笔记:oracle学习三:SQL语言基础之检索数据:简单查询、筛选查询

    目录 1. 检索数据 1.1 简单查询 1.1.1 检索所有列 1.1.2 检索指定的列 1.1.3 查询日期列 1.1.4 带有表达式的select语句 1.1.5 为列指定别名 1.1.6 显示不 ...

随机推荐

  1. 已有 JS 模块化和打包方案收集

    模块化方案 RequireJS AMD 方案, 常用的 define 语法, 异步加载模块, 目前很多支持: 官网 http://requirejs.org/ Github https://githu ...

  2. (一)phoneGap之环境搭建教程及其example分析

    phoneGap之环境搭建教程及其example分析 一.环境搭建 与普通的开发android应用一样,phoneGap也同于原生android应用一样,环境相同,只是有部分不同,下面就我做理解,进行 ...

  3. (简单) POJ 2253 Frogger,Dijkstra。

    Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Fro ...

  4. iOS开发——离线缓存

    先搭好架子,有时间了再填充.

  5. js 截取字符串里的ip

    var ip_reg = /([\d\.]*)/ig; ip = ip_reg.exec(str); return ip; ip_reg会截取 '(' 开始的字符串,中间包含数字和 '.' .

  6. linux获得目录下文件个数

    获得当前目录下文件个数赋值给变量panonum: panonum=$(ls -l |grep "^-" | wc -l) 获取指定目录下文件个数赋值给指定变量: panonum=$ ...

  7. Binary转换成Hex字符串

    想调优别人的代码,网上搜索一下Binary to Hexstring的转换,全是利用printf.scanf之类实现的,效率好低,还是自己想个简单的办法吧! .......此处省略一万字....... ...

  8. sqlite3API函数

    回顾: DDL 表的创建.修改.删除 create table 表名(字段名 字段类型 [约束],...); alter table 表名 {rename to 新名字 | add column 字段 ...

  9. CART分类与回归树 学习笔记

    CART:Classification and regression tree,分类与回归树.(是二叉树) CART是决策树的一种,主要由特征选择,树的生成和剪枝三部分组成.它主要用来处理分类和回归问 ...

  10. Angular - - $interval 和 $timeout

    $interval window.setInterval的Angular包装形式.Fn是每次延迟时间后被执行的函数. 间隔函数的返回值是一个承诺.这个承诺将在每个间隔刻度被通知,并且到达规定迭代次数后 ...