To find the Top 100 tables RowCnt, Fragmentation, Space Utilization and Datachange% (in terms of #Rows)
select top 100 "Table"=left(name,32), "#Rows"=row_count(db_id(), id), "DataChanged%"=datachange(name, NULL, NULL), "Space_Utilization"=derived_stat(object_id(name),0, 'sput'), "Fragmentation"=derived_stat(object_id(name),0, 'dpcr') from sysobjects
where type='U'
order by 2 desc
To Find all the indexes are not used in any Queries/Processes since last boot where type='U'
order by 2 desc
(This Query works only with MDA tables) :
select DatabaseName = convert(char(20), db_name()), TableName = convert(char(20), object_name(si.id, db_id())), IndexName = convert(char(20),si.name), IndexID = si.indid
from master..monOpenObjectActivity mo, sysindexes si
where mo.ObjectID =* si.id
and mo.IndexID =* si.indid
and (mo.UsedCount = 0 or mo.UsedCount is NULL)
and si.indid > 0
and si.id > 99 -- No system tables
order by 2, 4 asc
To find the Top 21 tables (in terms of #Indexes)
SELECT top 21 left(o.name,32), count(i.indid)
FROM sysobjects o, sysindexes i
where o.id = i.id
group by o.id
order by 2 desc
SELECT top 21 left(o.name,32), count(i.indid)
FROM sysobjects o, sysindexes i
where o.id = i.id
group by o.id
order by 2 desc
To find all the tables with LockScheme:
select DatabaseName = convert(char(20), db_name()), "TableName"=left(name, 32), row_count(db_id(),id) as "#Rows",
"lock_scheme" = case when (sysstat2 & 57334) < 8193 then "All Pages"
when (sysstat2 & 57334) = 163848193 then "Data Pages"
else "Data Rows" end
from sysobjects where type='U' order by 2 desc
To find all the Tables and their Triggers and Status.
select convert(varchar(30), name) as TableName,
convert(varchar(30), isnull(object_name(instrig), '')) as InsertTriggerName,
case sysstat2 & 1048576 when 0 then 'enabled' else 'disabled' end as InsertTriggerStatus,
convert(varchar(30), isnull(object_name(updtrig), '')) as UpdateTriggerName,
case sysstat2 & 4194304 when 0 then 'enabled' else 'disabled' end as UpdateTriggerStatus,
convert(varchar(30), isnull(object_name(deltrig), '')) as DeleteTriggerName,
case sysstat2 & 2097152 when 0 then 'enabled' else 'disabled' end as DeleteTriggerStatus
from sysobjects where type='U' and (instrig<>0 or updtrig<>0 or deltrig<>0)
order by name
To find the HostName and Server Details
select left(address_info,32) as "Server's Host Name & PortNumber"
,@@servername as "ASE Server Name"
,net_type as "N/W Protocol"
from master..syslisteners
.
No comments:
Post a Comment