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. java Conditions

    //Listing 7-2. Achieving Synchronization in Terms of Locks and Conditions import java.util.concurren ...

  2. composer 272解决

    composer global require "fxp/composer-asset-plugin:~1.0.3"                                 ...

  3. centos FTP服务器的架设和配置

    yum install vsftpd 2.启动/重启/关闭vsftpd服务器 [root@localhost ftp]# /sbin/service vsftpd restart Shutting d ...

  4. netbeans环境搭建

    1.下载文件http://pan.baidu.com/s/1kUu52mV 2.安装. 3.设置字体颜色,原先的太亮,我设置了保护色,参照sublime 我设置的字体高亮效果http://pan.ba ...

  5. Qt 之 去除窗口部件被选中后的焦点虚线框(设置Qt::NoFocus即可)

    http://blog.csdn.net/goforwardtostep/article/details/53420529

  6. IIS是如何处理ASP.NET请求的

    每次服务器接受到请求,都要先经IIS处理.这不是一篇描述ASP.NE生命周期的文章,仅仅是关于IIS操作的.在我们开始之前,先了解这些会有助于对全文的理解,同时欢迎反馈和建议. 什么是Web Serv ...

  7. 通过自定义属性存储数据实现输入框获得焦点与失去焦点改变value值

    http://gopro.ee.cagoe.com/index.html     html: <div class="name"><input value=&qu ...

  8. magento 图片缓存是如何生成的

    Varien_Image_Adapter_Gd2 类 ,里面有个save()方法,通过图片格式拼出来的方法  call_user_func_array($this->_getCallback(' ...

  9. 人脸pts文件检查及人脸框输出

    function output() outtxt = fopen('D:\AR database\kz.txt','wt'); : imgpath= strcat('D:\AR database\kz ...

  10. 详细解读Jquery的$.get(),$.post(),$.ajax(),$.getJSON()用法

    一,$.get(url,[data],[callback]) 说明:url为请求地址,data为请求数据的列表,callback为请求成功后的回调函数,该函数接受两个参数,第一个为服务器返回的数据,第 ...