public string IXToSqlString(SIndex index) { List <string> colcurr = new List <string>(); List <string> colcurrwitho = new List <string>(); foreach (var a in index.columns) { colcurr.Add(a.Key.name); colcurrwitho.Add(a.Key.name + " " + (a.Value == 1 ? "desc" : "asc")); } string indexname = string.Empty; if (index.isprimarykey) { indexname = "PK_" + index.table.name + "_"; } else if (index.isuniqueconstraint) { indexname = string.Format("UQ_{0}_{1}", index.table.name, string.Join("_", colcurr)); } else { indexname = string.Format("IX_{0}_{1}", index.table.name, string.Join("_", colcurr)); } string template = "create {0} index {1} on {2}({3});"; string s = string.Format(template, index.isclustered ? "clustered" : "nonclustered", indexname, index.table.name, string.Join(",", colcurrwitho)); return(s); }
public string IXToSqlString(SIndex index) { List <string> colcurr = new List <string>(); List <string> colcurrwitho = new List <string>(); foreach (var a in index.columns) { colcurr.Add(a.Key.name); colcurrwitho.Add(a.Key.name + " " + (a.Value == 1 ? "desc" : "asc")); } string indexname = string.Empty; if (index.isprimarykey) { indexname = "PK_" + index.table.name + "_"; } else if (index.isuniqueconstraint) { indexname = string.Format("UQ_{0}_{1}", index.table.name, string.Join("_", colcurr)); } else { string tname = string.Join("_", colcurr); if (tname.Length > 30) { // string tnames = Math.Abs(tname.GetHashCode()).ToString(); string rname = ""; for (int k = 0; k < 15; k++) { Random rd = new Random(k + 1 + DateTime.Now.Millisecond); rname += ((char)rd.Next(97, 123)).ToString(); System.Threading.Thread.Sleep(1); } tname = rname; } indexname = string.Format("IX_{0}_{1}", index.table.name, tname); } string template = "create {0} index {1} on {2}({3});"; string s = string.Format(template, "", indexname, index.table.name, string.Join(",", colcurrwitho)); return(s); }