zoukankan      html  css  js  c++  java
  • SQL server 基础语言


    --查询 基本语法  select 列名 from 表名 where 查询条件
    select ClassName from Student s,Class c where s.ClassId=c.Id and StudentName='张三'

    --模糊查询 有4中 第一种:_表示一个字符
    select * from Student where StudentName like '_三'

    --模糊查询 有4中 第二种:%表示很多个字符
    select * from Student where StudentName like '%三%'

    --模糊查询 有4中 第二种:[] 表示一个字符
    select * from Student where StudentName like '%[2-5]'

    --模糊查询 有4中 第二种:[^]表示一个字符
    select * from Student where StudentName like '%[^3,三]'

    --排序 默认为升序 asc 降序为desc order by
    select * from Student order by ClassId asc,StudentName desc

    --group by 分组 Count(*)查询总数的 having相当于where 但是接在group by 后面的
    --有having的时候 可以有where
    select ClassId,COUNT(*) as 人数 from Student where StudentName!='张三' group by ClassId having ClassId =1

    --Max最大值 Min最小值 COUNT()总数量 AVG平均数 SUM总和
    select * from Student
    select MAX(Id),StudentName from Student group by StudentName
    select Min(Id) from Student
    select Count(Id) from Student group by StudentName
    select AVG(Id) from Student group by StudentName
    select SUM(Id) from Student group by StudentName

    --插入语句
    --insert into 表名(列名) values(值)
    insert into Student values(2,'王五')

    --修改语句
    --update 表名 set 列名='值',列名='值' where 条件 (如果没有where条件,则这一列的值都被改变)
    update Student set StudentName='李四',ClassId=4 where Id=2

    --删除 删除从表 如果想要删除主表中的数据 需要先把从表删除完
    --delete 表名 where 条件 根据条件删除,删除过后 自增列不会发生改变
    delete Student where ClassId=4 and StudentName='李四'
    delete Student where ClassId=1
    delete Class where Id=1
    --删除整个表格的数据
    truncate table Student
    truncate table Class

  • 相关阅读:
    [nodejs]npm国内npm安装nodejs modules终极解决方案
    [nodejs]解决mysql和连接池(pool)自动断开问题
    [nodejs]国内npm安装nodejs modules失败的几个解决方案
    [less]用webstorm自动编译less产出css和sourcemap
    [javascript] Promise API
    [javascript]巧用sourcemap快速定位javascript中的问题
    Gruntjs提高生产力(四)
    Gruntjs提高生产力(三)
    Gruntjs提高生产力(二)
    Gruntjs提高生产力(一)
  • 原文地址:https://www.cnblogs.com/Sora-L/p/6915096.html
Copyright © 2011-2022 走看看