zoukankan      html  css  js  c++  java
  • 在DB中查找所有表的字符串字段是否有指定值


    declare @TableName nvarchar(100),@ColName nvarchar(100),@SQL nvarchar(4000),@TableID int,@FindValue nvarchar(100)

    SET @FindValue = 'sp_CopyInterventionDffToInspectionReportDff'

    DECLARE TCur Cursor
     FOR SELECT NAME,ID FROM sysobjects
      WHERE Xtype = 'U'
    OPEN TCur
    FETCH NEXT FROM TCur INTO @TableName,@TableID

    WHILE @@FETCH_STATUS = 0
    BEGIN
     DECLARE CCur CURSOR
      FOR SELECT Name FROM syscolumns WHERE ID = @TableID AND Xtype = 231
     OPEN CCur
     FETCH NEXT FROM CCur INTO @ColName

     WHILE @@FETCH_STATUS = 0
     BEGIN
      SET @SQL = 'IF EXISTS(SELECT * FROM ' + @TableName + ' WHERE ' + @ColName + ' = ''' + @FindValue + ''')'
      SET @SQL = @SQL + 'PRINT ''' + @TableName + ''' + '' + '' + ''' + @ColName + ''''
      EXEC (@SQL)
      --print @sql

      FETCH NEXT FROM CCur INTO @ColName
     END
     CLOSE CCur
     DEALLOCATE CCur
      
     FETCH NEXT FROM TCur INTO @TableName,@TableID
    END
    CLOSE TCur
    DEALLOCATE TCur

  • 相关阅读:
    svn不提交.net项目中的bin
    java 与C# 时间格式 交互
    生成菜单序列号
    ashx 方法模板
    webservice使用方法
    如何配置IIS服务器?
    zepto.fullpage
    模拟单选框
    star score
    Hover show tips
  • 原文地址:https://www.cnblogs.com/micolour/p/2397446.html
Copyright © 2011-2022 走看看