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;
                }
            }

  • 相关阅读:
    理解JavaScript的数值型数据类型
    The First Article
    DOS符号转义(转 http://www.robvanderwoude.com/escapechars.php)
    symfony中doctrine常用属性
    Node中的promise简说及入门
    DOM操作三
    DOM操作二
    DOM操作一
    JavaScript算法题(二) && 数组filter使用
    简说 call() 、apply() 、bind()
  • 原文地址:https://www.cnblogs.com/soundcode/p/2511092.html
Copyright © 2011-2022 走看看