/// <summary> /// Load all index properties /// </summary> public void LoadAllProperties( ) { string cmdText = "SELECT case when(I.status & 16) = 16 then 1 else 0 end as [clustered],"; cmdText += " case when(I.status & 1) = 1 then 1 else 0 end as [IgnoreDupKey],"; cmdText += " case when(I.status & 16777216) = 16777216 then 1 else 0 end as [NoRecompute],"; cmdText += " case when(I.status & 256) = 256 then 1 else 0 end as [PadIndex],"; cmdText += " case when(I.status & 2) = 2 then 1 else 0 end as [unique],"; cmdText += " FILEGROUP_NAME(I.groupid) as [filegroup],"; cmdText += " I.OrigFillFactor"; cmdText += " FROM sysobjects O,sysindexes I "; cmdText += " WHERE I.indid = " + ID.ToString() + " AND O.id = " + OwnerObjectId.ToString(); cmdText += " AND I.status&2048!=2048 AND I.status&4096!=4096 AND I.id=O.id AND type in ('U','V') "; cmdText += " AND (INDEXPROPERTY(I.id,I.name,'IsStatistics') <> 1) AND (INDEXPROPERTY(I.id,I.name,'IsAutoStatistics') <> 1) "; cmdText += " AND (INDEXPROPERTY(I.id,I.name,'IsHypothetical') <> 1) AND O.type!='S'"; using (SqlConnection conn = _cp.CreateSqlConnection(true, false)) { SqlDataReader reader = DbCmd.ExecuteReader(cmdText, conn); try { while (reader.Read()) { this.Clustered = Convert.ToBoolean(reader.GetValue(0)); _ignoreDupKey = Convert.ToBoolean(reader.GetValue(1)); _noRecompute = Convert.ToBoolean(reader.GetValue(2)); _padIndex = Convert.ToBoolean(reader.GetValue(3)); _unique = Convert.ToBoolean(reader.GetValue(4)); this.FileGroup = reader.GetValue(5).ToString(); this.FillFactor = Convert.ToInt32(reader.GetValue(6)); } } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } } }
public DataTable GetStatistics( ) { string cmdText = "SELECT id, indid, name, dpages,reserved,used,minlen,xmaxlen,rowmodctr,maxirow,lockflags,pgmodctr FROM sysindexes WHERE id=" + OwnerObjectId.ToString() + " AND indid='" + this.ID.ToString() + "'"; return(DbCmd.ExecuteDataTable(cmdText, _cp)); }