• SQL基础1


    insert into TblStudent(tSName,tSGender,tSClassId)
    select 'name','男',1 union all
    select 'name','男',1
    多条插入

    什么时候需要在汉字N'男'
    当数据类型为varchar并且不是中文排序规则

    删除表中所有数据
    delete from 表名
    truncate table 表名 比较快 最小方式记录日志,自动编号重置,不触发delete触发器
    drop table 表名 删除表


    percent 百分比 select top 10 percent * from tblStudent where tsAge is not null order by tsAge asc


    任何聚合函数都不计算null值,count(age) 如果age列有null那么不算。


    select * from TblStudent where tSAge>=20 or tSAge<=30 快
    select * from TblStudent where tSAge between 20 and 30 会转换
    select * from TblStudent where tSAge in(20,21,22,23,24,25,26,27,28,29,30) 这种不会转换成>= <= 也有not in


    类型转换
    select '张三'+cast(18 as char(2))
    select '张三'+CONVERT(char(2),18) convert的第三个参数为样式号


    联合union 就是竖向合并对应的列要兼容
    select tSName,tSGender from TblStudent union
    select tTName,tTGender from TblTeacher
    union会把重复数据去掉 union all 实际多少就是多少


    一次插入多条数据
    insert into Score(studentId,English,Math)
    select 1500 union
    select 1500 union
    select 1200 union all
    select 13
    这里同样会去除重复

    如果表不存在
    select * into NewStudent from TblStudent
    将TblStudent中的数据导入NewStudent中,表不存在会创建,存在会报错 不会创建约束

    select * into NewStudent from tblStudent where 1<>1 会创建相同的表,没有数据 不满足条件,分数据库 有可能逐条比较
    select top 0 * into NewStudent from tblStudent 也可以

    向表追加别的表数据
    insert into NewStudent select tsName from tblStudent

  • 相关阅读:
    [洛谷P2523] HAOI2011 Problem c
    [CF156D] Clues
    [洛谷P4769] NOI2018 冒泡排序
    [CF605E] Intergalaxy Trips
    [洛谷P4492] HAOI2018 苹果树
    [洛谷P3349] ZJOI2016 小星星
    [洛谷P4336] SHOI2016 黑暗前的幻想乡
    [洛谷P5364] SNOI2017 礼物
    [洛谷P2606] ZJOI2010 排列计数
    [洛谷P6078] CEOI2004 candy
  • 原文地址:https://www.cnblogs.com/woge/p/4194627.html
Copyright © 2020-2023  润新知