zoukankan      html  css  js  c++  java
  • sql 2005判断某个表或某个表中的列是否存在

    /// <summary>
            /// 判断是否存在某表的某个字段
            /// </summary>
            /// <param name="tableName">表名称</param>
            /// <param name="columnName">列名称</param>
            /// <returns>是否存在</returns>
            public static bool ColumnExists(string tableName, string columnName)
            {
                string sql = "select count(1) from syscolumns where [id]=object_id('" + tableName + "') and [name]='" + columnName + "'";
                object res = GetSingle(sql);
                if (res == null)
                {
                    return false;
                }
                return Convert.ToInt32(res) > 0;
            }

    /// <summary>
            /// 表是否存在
            /// </summary>
            /// <param name="TableName"></param>
            /// <returns></returns>
            public static bool TabExists(string TableName)
            {
                string strsql = "select count(*) from sysobjects where id = object_id(N'[" + TableName + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1";
                //string strsql = "SELECT count(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + TableName + "]') AND type in (N'U')";
                object obj = GetSingle(strsql);
                int cmdresult;
                if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
                {
                    cmdresult = 0;
                }
                else
                {
                    cmdresult = int.Parse(obj.ToString());
                }
                if (cmdresult == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

  • 相关阅读:
    linux-centos7-vmware 虚拟机 设置静态 ip 地址,采用 nat 模式,实现连接公网
    mysql_5.7.20 二进制包 在Linux系统中的 安装和配置
    解决windows系统80端口被占用问题
    应用系统架构演变初探
    fastdfs-nginx扩展模块源码分析
    心已落定,入驻博客园
    mac iterm 提示符序列调整
    Background removal with deep learning
    git push fatal: The remote end hung up unexpectedly
    mac sed 使用踩坑实录
  • 原文地址:https://www.cnblogs.com/soundcode/p/2511092.html
Copyright © 2011-2022 走看看