博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL语句
阅读量:4331 次
发布时间:2019-06-06

本文共 1863 字,大约阅读时间需要 6 分钟。

T-SQL语句:

创建表:create table name( code varchar(50),)
主键:primary key
非空:not null
自增长:auto_increment
外键:references
删除表: drop table family
创建数据库:create database mydb
删除数据库:drop database mydb
CRUD操作:
    C: create
    增加数据:
    insert into nation values('n001','汉族')--普通添加
    insert into nation values('','','')  -- 自增长列也要添加
    insert into nation (code) values ('n002')--往表中添加特定列的数据
    
    R: read
    
    查询数据:
    1、查询所有数据   select * from info
    查特定列  select code,name from info
    2、根据条件差
    select * from info where code='p001'  一个条件查询
    select * from info where code='p001' and nation ='n001'  多条件 并关系  查询
    select * from info where code='p001' or nation = 'n001'  多条件  或关系
    select * from car where price>=50 and price <= 60    范围查询
    select * from car where price between 50 and 60
    3、模糊查询
    select * from car where name like '%型'    已型为结束的数据 ------》  %通配符代表任意多个字符
    select * from car where name like'%奥迪%'
    select * from car where name like'_马%'
    4、排序
    select * from car order by price asc    按照价格升序排列(默认)asc 可以省去不写
    select * from car order by price desc   按照价格降序排列
    select * from car order by price desc ,oil desc   按照两列进行排序  前面的为主要
    5、统计函数(聚合函数)
    select count(code) from car   查询表中有多少条数据
    select max(price) from car    取价格中最大值
    select min(price) from car    取价格最小值
    select sum(price) from car     取价格的总和
    select avg(price) from car    取价格的平均值
    6、分组查询
    select * from car group by brand
    select brand from car group by brand        
    select count(brand) from car group by brand     获取分组每组的数量
    select brand from car group by brand having count(*)>2   分组后筛选数量大于2的
    7、分页查询
    select * from car limit m,n    跳过m条数据去n条数据
    
    8、去重查询
    select distinct  brand from car
    U:update
    修改数据:
    update nation set name = '回族'  ---全部修改
    update nation set name = ‘汉族’ where code = 'n002' --修改某一条数据
    update nation set code = 'n003' where name = '汉族'
    D:delete
    删除数据:
    delete from nation--删除整个表中的数据
    delete from nation where code = 'n001'   删除一条数据,已主键查询删除一条,如果以别的数据查询可能删除多条--重名。

转载于:https://www.cnblogs.com/youshashuosha/p/5130687.html

你可能感兴趣的文章
xml解析
查看>>
centos安装vim
查看>>
linux工作调度(计划任务)
查看>>
hdu--1698 Just a Hook(线段树+区间更新+懒惰标记)
查看>>
Python学习笔记-EXCEL操作
查看>>
输出保留12位小数的浮点数
查看>>
LnTbtbKLyv
查看>>
springboot ---> spring ioc 注册流程 源码解析 this.prepareContext 部分
查看>>
Java基础随笔
查看>>
图的存储结构
查看>>
图的遍历
查看>>
最小生成树的基本算法
查看>>
MySQL基础操作
查看>>
cf 1004 D Sonya and Matrix
查看>>
求幂塔函数
查看>>
机器学习常用性能度量中的Accuracy、Precision、Recall、ROC、F score等都是些什么东西?...
查看>>
目标检测中常提到的IoU和mAP究竟是什么?
查看>>
eclipse运行mapreduce的wordcount
查看>>
linux命令帮助 man bash
查看>>
springmvc 参数解析绑定原理
查看>>