zoukankan      html  css  js  c++  java
  • sql语句巩固

    查询每行随机值

    if(object_id('tempdb..#cc','U')is not null)
    drop table #cc
    go
    declare @a int
    set @a=0
    while @a<15
    begin
    if @a=0
    select floor(rand()*3)+3 as cc into #cc
    else
    insert into #cc values( floor(rand()*3)+3 )
    set @a=@a+1
    end
    select * from #cc

    连接查询

    select a.Class_Content,*from T1103.dbo.T101_1
    inner join (SELECT Class_Code, Class_Content FROM   WssMng_SXZ.dbo.ClassTable
                        WHERE (Fk_ClassName = '案件来源')) as a on a.Class_Code = T101_1.M101_1_111
    where unitID ='130800'

    触发器 批量更新

    declare @startid int
    declare @j int
    select @k = 5,@startid = 1

    declare c_update_id cursor for
    select ID from TABLE for update

    open c_update_id

    fetch next from c_update_id into @startid
    while(@@fetch_status=0)
    begin
     update TABLE set nid =  @j where ID= @startid
     fetch next from c_update_id into @startid
     select @j = @j + 1
    end

    CLOSE c_update_id
    DEALLOCATE c_update_id

    --批量更新

    declare @id int
    set @id = 0
    update table set nid=@id,@id=@id+1


    --查询表中约束字段名称

    select b.name from sysobjects b join syscolumns a on b.id = a.cdefault

    --删除存在的约束

    exec('alter table TableName drop constraint ' + TABLE)

    --给字段加注视

    EXEC sp_addextendedproperty 'MS_Description', '描述', 'user', dbo, 'table', tablename, 'column', columnid

    --随机数据

    SELECT cast(floor(rand()*99999999) AS Bigint)

    --newid

    select abs(CHECKSUM(NEWID()))

    select left(100000000 + CONVERT(bigint, ABS(CHECKSUM(NEWID()))), 8)

  • 相关阅读:
    0、前端页面的请求路径
    5、Spring事务
    4、Spring整合MyBatis
    2.3、Spring多配置文件
    2.2、基于注解的DI注入
    Rest语法,传入多个参数
    JS中 `=+` 是什么?
    Node.js 爬虫爬取电影信息
    JavaScript监听页面可见性(焦点)同时改变title的三种方法
    CSS 清除浮动的方法
  • 原文地址:https://www.cnblogs.com/likeyou/p/3067234.html
Copyright © 2011-2022 走看看