zoukankan      html  css  js  c++  java
  • sql 总结

    --select...from...where...  查询
    --insert into...values()  插入
    --update...set...   改
    --delete from...where...  删
    --drop table ..删除表
    --top 查询前几行。跟在select后面
    --distinct 去掉重复
    --order by desc 降序 asc 升序 order by 后边跟多个排序,先排前面的,然后在不改变前面的基础上在排序后边的!
    --分组   group by 后边跟列名,对那一列排序就显示那一列!!
    -- + - * /  算数运算符 <= >= 比较用算符
    -- 逻辑用算符  and or not
    -- all any some in not 
    --in 在什么范围之类 in(,),not in(,)
    --子查询 就是使用查询语句查询一列数据,作为其他查询语句的的条件的参数  .. 相关子查询--是同一个表的子查询
    --外键 受约束的表叫外键表,约束的数据源叫主键表;要想加外键,必须有主键; 要想删外键表,必须删主键表;
    --作为外键的数据源的列,必须要是唯一键。选一列必须是主键或unique。
    --时间日期函数:year(时间日期列) , month(),day() ,datediff(year,csrq,getdate()) as age getdate()当前系统日期时间 
    --union all  纵链接
    --isdate() 判断一个时间是否为datetime     //msdn查找
    --dateadd(day,5,''),   print( datename(weekday,'2015-4-23')),
    -- 表链接 union all。。。注意:列数对应,列的先后顺序对应。any, all 只能在比较运算符一起使用
    --ltrim rtrim 去除空格
    --substring('',1,2) 截取字符串
    --replace('','','') 替换
    --space() 空格
    --patindex  索引
    --stuff('', , ,'')插入
    --cast(''as int)   convert(int,'')类型转换
    --abs() 绝对值 ceiling 上线  floor  下线 
    --存储过程   declare 定义变量 ,@开头,  
    /*declare @bianliang int
    set @bianliang =10  变量赋值
    select @bianliang
    print @bianliang
    eg: declare @bianliang1 int,@bianliang2 int
    set @bianliang1 =1
    set @bianliang2=2
    select @bianliang1+bianliang2
    */
    --create proc(procedure) 存储过程名 创建存储过程 
    --as 中间写存储过程内容
    --select* from  
    --go 
    --存储过程创建之后,会存储到对应数据库的可编程性->存储过程文件夹
    --exec 存储过程名  执行存储过程
    /*
    create proc(procedure) returncount
    as 
    declare @a int
    select @a=count (* )from  Student
    return @a
    go 
    declare @jieshou int
    exec @jieshou=returncount
    print @jieshou
    */
    --带参数的存储过程
    /*
    create proc(procedure) returncount
    @a int, //输入参数 ,用逗号隔开
    @b int
    as 
      return @a+@b
    go 
    declare @c int
    exec @c=returncount 3,5  带参数的存储过程,需要存储过程名后输入参数,用空格隔开,参数之间用逗号隔开
    print @c
    */
    /*
    create proc p
    @a int //输入参数 ,用逗号隔开
    as 
      if(@a>0 and @a<2)
      begin
           return @a
      end
    go 
    declare @c int
    exec @c=p 3  
    print @c
    */
    --视图  view  就是一个虚拟的表
    --create view view_1 as   删除 drop  修改 alter
    --子查询查询出的结果集可以作为一个表使用   ()as table名
    --分页查询 
    --select top 2 * from Student where Sno not in (select top 4 Sno  from Student )
    /*create proc wannengfenye
    @nowye int,--当前页
    @numbers int, --一显示行数
    @tablename varchar(50),--表名
    @zhujian varchar(50)--表的主键
    as
    exec ('select top ('+@numbers+') *from '+@tablename+'  where '+@zhujian+' not in
     (select top (('+@nowye+'-1)*'+@numbers+') '+@zhujian+' from '+@tablename+' )')
    go
    exec wannengfenye 2,1,'student','sno'
    */
    --约束  对列的数据值起一个约束作用,规定列支的范围;  主键 primary key,外键 reference key,非空 not null,自增长identity(),唯一 unique,check约束
    --set 数据库给变量赋值用set
    --数据库的备份 在不影响源数据库的运行情况下,将数据库备份到一个.bank结尾的文件下;备份还原  将 bank文件还原到数据库
    --右键 任务 备份     数据库右键 还原数据库
    --分离 将数据库与数据库服务分离,附加  将数据库mdf文件,附加到数据库上
    --右键 任务 分离 mdf文件   数据库右键  附加
    --触发器 trigger   就是一种特殊的存储过程 , 触发器是通过对数据库的操作,来引发。存储过程是通过认为的exec来执行。
    --create trigger student_insert 触发器名   on student 触发器所在的表 
    --for(after)/(instead of) insert (update/delete) 在执行insert之后自动执行操作 as ......go 
    --deleted 是一个临时表,里边存着你有删除的数据  as select * from deleted go 
    
  • 相关阅读:
    学习进度条
    软件工程---课程设计总结
    软件工程----课程总结
    操作系统--实验四
    软件工程---阅读《构建之法》P384~391
    软件工程---阅读《构建之法》第8、9、10章读后感
    操作系统---实验三 进程调度模拟程序
    软件工程--- 阅读《构建之法》第6~7章
    转载---CSS3实现曲线阴影和翘边阴影
    转载---QRcodeJS生成二维码
  • 原文地址:https://www.cnblogs.com/lushixiong/p/4465473.html
Copyright © 2011-2022 走看看