1.删除表

drop  table +表名

2.修改表

alter  table+表名+ add(添加)+列名+ int(类型)

alter  table+表名+ drop(删除)+column(列)+列名

3.删除数据库

Drop  datebase +库名

CRUD操作

C代表create 添加数据

R代表 read  读取数据

U代表update 修改数据

D代表delete 删除数据

1.添加数据

Insert(插入/添加) into+ 表名+ values(添加的值) ,‘    ’转换字符串

Insert  into Nation values(‘n002’,‘回族’)

Insert  into Nation values(‘n003’,‘’)

多列添加:Insert  into  Nation(code,name) values(‘n003’,‘维吾尔族’)

Insert  into friends values(‘p003’,‘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 0il 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 
sum(price) from car 求和

select 
sum(price) from car 求和

select 
sum(price) from car 求和

数据库 CRUD的更多相关文章

  1. 【转】数据库CRUD操作

    数据库CRUD操作 一.删除表   drop table 表名称 二.修改表 alter   table 表名称 add  列名 数据类型   (add表示添加一列) alter  table  表名 ...

  2. MySQL数据库CRUD命令用法

    数据库CRUD操作即添加(Create).读取(Read).更新(Update)和删除(Delete). 1. 添加操作也称插入操作,使用Insert语句,Insert语句可以用于几种情况: 插入完整 ...

  3. 10月16日下午MySQL数据库CRUD操作(增加、删除、修改、查询)

    1.MySQL注释语法--,# 2.2.后缀是.sql的文件是数据库查询文件. 3.保存查询. 关闭查询时会弹出提示是否保存,保存的是这段文字,不是表格(只要是执行成功了表格已经建立了).保存以后下次 ...

  4. 数据库CRUD操作:C:create创建(添加)、R:read读取、U:update:修改、D:delete删除;高级查询

    1.注释语法:--,#2.后缀是.sql的文件是数据库查询文件3.保存查询4.在数据库里面 列有个名字叫字段   行有个名字叫记录5.一条数据即为表的一行 CRUD操作:create 创建(添加)re ...

  5. jdbc 连接各种数据库 CRUD

    一,jdbc简介 SUN公司为了简化.统一对数据库的操作,定义了一套Java操作数据库的规范(接口),称之为JDBC.这套接口由数据库厂商去实现,这样,开发人员只需要学习jdbc接口,并通过jdbc加 ...

  6. 数据库CRUD操作以及MyBatis的配置使用

    • 业务字段设计 • 数据库创建 • CRUD操作 • MyBatis集成 • 注解和XML定义 • ViewObject和DateTool • 首页开发     • 业务字段设计 实体: name: ...

  7. django notes 六:数据库 CRUD 操作

    CRUD 也没什么可说的,django 提供了完善的 orm  api, 直接用就行了. 我只贴几个列子,一看就明白了,自己再用用就熟了. # create b = Blog(name='Beatle ...

  8. SQL数据库 CRUD

    1.删除表 drop  table +表名 2.修改表 alter  table+表名+ add(添加)+列名+ int(类型) alter  table+表名+ drop(删除)+column(列) ...

  9. MySQL数据库 crud语句 ifnull() 创建新账户 备份数据库 一对多关系 多对多(中间表) 外键约束 自关联 子查询注意事项 DML DDL DQL mysql面试题 truncate与delete的区别

    DML(data manipulation language): 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言 DDL ...

随机推荐

  1. Linux下安装Xdebug

    为了调试PHP程序,安装一下xdebug. 官方网址: http://www.xdebug.org 首先下载xdebug2.1.0,在官方首页下载源代码,下载回来的文件名是:xdebug-2.1.0. ...

  2. 【转】设计模式(十一)代理模式Proxy(结构型)

    设计模式(十一)代理模式Proxy(结构型) 1.概述 因为某个对象消耗太多资源,而且你的代码并不是每个逻辑路径都需要此对象, 你曾有过延迟创建对象的想法吗 ( if和else就是不同的两条逻辑路径) ...

  3. oracle 嵌套表

    --自定义对象 CREATE OR REPLACE TYPE Fas_checksheetinfo_line_obj AS OBJECT(  CSID_ID           VARCHAR2(32 ...

  4. 【Android测试】【第九节】MonkeyRunner—— 初识

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/4836815.html 不得不说两句,过了这么久才再次更新博 ...

  5. zepto-创建dom

    在使用zepto时,为了使得ajax请求回来的数据添加到页面上之后,不至于失去所绑定的事件. 我一般会采用$()创建dom元素节点,然后添加所需要的class和html等等一系列的样式,最基本的是$( ...

  6. github添加SSH Key

    1.背景介绍 缘由:在github上下载goagent时出现错误. 在终端使用命令:git clone git@github.com:phuslu/goagent.git 会报权限错误如下: Clon ...

  7. .SQL Server中 image类型数据的比较

    原文:.SQL Server中 image类型数据的比较 在SQL Server中如果你对text.ntext或者image数据类型的数据进行比较.将会提示:不能比较或排序 text.ntext 和 ...

  8. ArcGIS API for Silverlight中加载Google地形图(瓦片图)

    原文:ArcGIS API for Silverlight中加载Google地形图(瓦片图) 在做水利.气象.土地等行业中,若能使用到Google的地形图那是再合适不过了,下面就介绍如何在ArcGIS ...

  9. JS手册目录

    1.控件篇1.1 文本框 1.2 文本域 1.3 单选按钮 1.4 复选按钮 1.5 下拉列表框 1.6 文件上传组件 1.7 提交按钮 版权所有,转载请注明作者出处. 2016年7月26日15:54 ...

  10. 微信小程序:开发之前要知道的三件事

    前言 微信之父张小龙在年初的那次演讲中曾表示:"我自己是很多年的程序员,我觉得我们应该为开发的团队做一些事情".几个月后,微信正式推出微信应用号(即微信小程序),在互联网中掀起了又 ...