zoukankan      html  css  js  c++  java
  • Sqlserver 2008:sp_msforeachdb 坑爹的错误陷阱

    不多说。看代码

    -- 一般的写法,可能错误 1
    exec sp_msforeachdb
    '
    if ''?'' like ''edb_a_____''
    begin
        if not exists
        (
            select *
            from ?.dbo.sysobjects a inner join ?.dbo.syscolumns b on a.id=b.id
            where a.name=''WFPUSER_T1480'' and b.name=''TC1364''
        )
        begin
            raiserror(''?'',14,1)
        end
        else
            print ''ok''
    end
    
    '
    
    -- 一般的写法,可能错误 2
    exec sp_msforeachdb
    '
    use ?
    
    if ''?'' like ''edb_a_____''
    begin
        if not exists
        (
            select *
            from sysobjects a inner join syscolumns b on a.id=b.id
            where a.name=''WFPUSER_T1480'' and b.name=''TC1364''
        )
        begin
            raiserror(''?'',14,1)
        end
        else
            print ''ok''
    end
    
    '

    确保正确的写法:

    -- 对比 0
    exec sp_msforeachdb
    '
    
    if ''?'' like ''edb_a_____''
    begin
        if not exists
        (
            select *
            from [?].dbo.sysobjects a inner join [?].dbo.syscolumns b on a.id=b.id
            where a.name=''WFPUSER_T1480'' and b.name=''TC1364''
        )
        begin
            raiserror(''?'',14,1)
        end
        else
            print ''ok''
    end
    
    '
    
    -- 对比 1 
    exec sp_msforeachdb
    '
    if ''?'' like ''edb_a_____''
    begin
        if not exists
        (
            select *
            from [?]..sysobjects a inner join [?]..syscolumns b on a.id=b.id
            where a.name=''WFPUSER_T1480'' and b.name=''TC1364''
        )
        begin
            raiserror(''?'',14,1)
        end
        else
            print ''ok''
    end
    
    '
    
    -- 对比 2 
    exec sp_msforeachdb
    '
    use [?]
    
    if ''?'' like ''edb_a_____''
    begin
    
        if not exists
        (
            select *
            from dbo.sysobjects a inner join dbo.syscolumns b on a.id=b.id
            where a.name=''WFPUSER_T1480'' and b.name=''TB0079''
        )
        begin
            raiserror(''?'',14,1)
        end
        else
            print ''ok''
            
    end
    
    '
    
    -- 对比 3
    exec sp_msforeachdb
    '
    use [?]
    
    if ''?'' like ''edb_a_____''
    begin
    
        if not exists
        (
            select *
            from sysobjects a inner join syscolumns b on a.id=b.id
            where a.name=''WFPUSER_T1480'' and b.name=''TB0079''
        )
        begin
            raiserror(''?'',14,1)
        end
        else
            print ''ok''
            
    end
    
    '
  • 相关阅读:
    Cesium中的坐标系及转换
    Cesium Workshop
    window.postMessage 跨窗口,跨iframe javascript 通信
    VUE课程参考---7、跑马灯效果
    VUE课程---9、事件绑定v-on
    VUE课程---8、属性绑定v-bind
    VUE课程---7、解决插值表达式闪烁问题
    小谈chrome调试命令:console.log的使用
    Hadoop平台配置总结
    hadoop 关闭进程时报错no 进程 to stop
  • 原文地址:https://www.cnblogs.com/jinzhenshui/p/2605163.html
Copyright © 2011-2022 走看看