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

  • 相关阅读:
    猜数字游戏,猜三次都不对,则结束游戏,猜一次就成功,结束游戏
    用return关键字实现1——100累加求和,返回总和并接收输出
    用return关键字实现求和操作
    return关键字的作用和接受实验
    数组各元素随机赋值、求和、求平均值、求最大值的各类测试(一维数组)
    日期下拉选择
    22--
    css 17课--
    css盒模型
    css学习
  • 原文地址:https://www.cnblogs.com/Sora-L/p/6915096.html
Copyright © 2011-2022 走看看