Пример #1
0
        private string ResumeIdentityCol(SIdentityAttribute id)
        {
            string template = " alter table {0} change {1} {2};";
            string s        = string.Format(template, id.column.table.name, id.column.name, ColToSqlString(id.column, true));

            return(s);
        }
Пример #2
0
        private string IdentityToPKSql(SIdentityAttribute id)
        {
            string template = " primary key ({0})";
            string s        = string.Format(template, id.column.name);

            return(s);
        }
Пример #3
0
        private string IdentityToPKSqlOutter(SIdentityAttribute id)
        {
            string template = " alter table {0} add constraint PK_{0} primary key({1});";
            string s        = string.Format(template, id.column.table.name, id.column.name);

            return(s);
        }
Пример #4
0
        private List <SIdentityAttribute> GetIdentityAttributes(DbConn dbconn, string tableid, List <SColumn> columns)
        {
            string    sql1 = "select object_id,name,column_id,seed_value,increment_value,last_value from sys.identity_columns where object_id=@objid";
            DataTable tb   = dbconn.SqlToDataTable(sql1, new { objid = tableid });
            List <SIdentityAttribute> identitys = new List <SIdentityAttribute>();

            foreach (DataRow dr in tb.Rows)
            {
                string cn = dr["name"].ToString();
                var    r  = columns.FirstOrDefault(x => x.name == cn);
                if (r == null)
                {
                    throw new Exception(cn + "在表中不存在");
                }
                var iden = new SIdentityAttribute()
                {
                    column    = r,
                    send      = Convert.ToInt64(dr["seed_value"]),
                    crement   = Convert.ToInt64(dr["increment_value"]),
                    lastvalue = (dr["last_value"] == null || dr["last_value"].ToString() == "") ? (Convert.ToInt64(dr["seed_value"]) - 1) : Convert.ToInt64(dr["last_value"])
                };
                r.isidentity        = true;
                r.identityattribute = iden;
                identitys.Add(iden);
            }
            return(identitys);
        }