May 17, 2026, 11:40 PM
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
select schema_name(o.schema_id) as [schema_name] ,
|
||||
object_name(o.object_id) as [table_name] ,
|
||||
i.name as [index_name] ,
|
||||
i.type_desc as [index_type] ,
|
||||
dmv.page_count ,
|
||||
dmv.fragment_count ,
|
||||
round(dmv.avg_fragment_size_in_pages, 2, 2) [avg_fragment_size_in_pages] ,
|
||||
round(dmv.avg_fragmentation_in_percent, 2, 2) [avg_fragmentation_in_percent] ,
|
||||
case when dmv.avg_fragmentation_in_percent <= 5 then 'RELAX'
|
||||
when dmv.avg_fragmentation_in_percent <= 30 then 'REORGANIZE'
|
||||
when dmv.avg_fragmentation_in_percent > 30 then 'REBUILD'
|
||||
end as [action] ,
|
||||
stats_date(dmv.object_id, i.index_id) as stats_update_date ,
|
||||
case when isnull(ps.function_id, 1) = 1 then 'NO'
|
||||
else 'YES'
|
||||
end as partitioned ,
|
||||
coalesce(fg.name, fgp.name) as [file_group_name] ,
|
||||
p.partition_number as [partition_number] ,
|
||||
p.rows as [partition_rows] ,
|
||||
prv_left.value as [partition_lower_boundary_value] ,
|
||||
prv_right.value as [partition_upper_boundary_value] ,
|
||||
case when pf.boundary_value_on_right = 1 then 'RIGHT'
|
||||
when pf.boundary_value_on_right = 0 then 'LEFT'
|
||||
else 'NONE'
|
||||
end as [partition_range] ,
|
||||
pf.name as [partition_function] ,
|
||||
ds.name as [partition_scheme]
|
||||
from sys.partitions as p with ( readpast )
|
||||
inner join sys.indexes as i with ( readpast ) on i.object_id = p.object_id
|
||||
and i.index_id = p.index_id
|
||||
inner join sys.objects as o with ( readpast ) on o.object_id = i.object_id
|
||||
inner join sys.dm_db_index_physical_stats(db_id(), null, null, null,
|
||||
N'LIMITED') dmv on dmv.OBJECT_ID = i.object_id
|
||||
and dmv.index_id = i.index_id
|
||||
and dmv.partition_number = p.partition_number
|
||||
left join sys.data_spaces as ds with ( readpast ) on ds.data_space_id = i.data_space_id
|
||||
left join sys.partition_schemes as ps with ( readpast ) on ps.data_space_id = ds.data_space_id
|
||||
left join sys.partition_functions as pf with ( readpast ) on pf.function_id = ps.function_id
|
||||
left join sys.destination_data_spaces as dds with ( readpast ) on dds.partition_scheme_id = ps.data_space_id
|
||||
and dds.destination_id = p.partition_number
|
||||
left join sys.filegroups as fg with ( readpast ) on fg.data_space_id = i.data_space_id
|
||||
left join sys.filegroups as fgp with ( readpast ) on fgp.data_space_id = dds.data_space_id
|
||||
left join sys.partition_range_values as prv_left with ( readpast ) on ps.function_id = prv_left.function_id
|
||||
and prv_left.boundary_id = p.partition_number
|
||||
- 1
|
||||
left join sys.partition_range_values as prv_right with ( readpast ) on ps.function_id = prv_right.function_id
|
||||
and prv_right.boundary_id = p.partition_number
|
||||
where objectproperty(p.object_id, 'ISMSShipped') = 0
|
||||
order by [avg_fragmentation_in_percent] DESC,
|
||||
[table_name] ,
|
||||
[index_name]
|
||||
@@ -0,0 +1,3 @@
|
||||
create table #SVer(ID int, Name sysname, Internal_Value int, Value nvarchar(512)) insert #SVer exec master.dbo.xp_msver
|
||||
declare @SmoRoot nvarchar(512)
|
||||
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\Setup', N'SQLPath', @SmoRoot OUTPUT
|
||||
@@ -0,0 +1,43 @@
|
||||
select rtrim(CONVERT(char(256), SERVERPROPERTY('servername'))) as SQLInstance, a.name as LoginName,
|
||||
isnull(type_desc, '') as type_desc, isntname, isntgroup, isntuser, isnull(is_disabled, 0) as is_disabled
|
||||
-- , createdate, updatedate, dbname, is_policy_checked, is_expiration_checked
|
||||
, a.sysadmin, a.securityadmin
|
||||
-- , a.serveradmin, a.setupadmin, a.processadmin, a.diskadmin, a.dbcreator, a.bulkadmin
|
||||
from master.sys.sql_logins x right outer join master.sys.syslogins a on x.name = a.name
|
||||
-- select * from master.sys.syslogins
|
||||
--where a.name not in ('sa','sql_sa','NT AUTHORITY\SYSTEM','NT SERVICE\MSSQLSERVER','PL\IBMSQLAdminsPL',
|
||||
-- 'PL\SSSAITMSQLAGT','NT SERVICE\SQLSERVERAGENT','PL\YGAPSDD_SQL','ELIFE\sssITMSQLsrv','ELIFE\sssLogShippingSQL',
|
||||
-- 'ELIFE\ElSrv_Clu','PLDEV\Local IBM SQL Admins','PLDEV\Local SDD SQL','sssLogShippingSQL')
|
||||
-- and a.name not like '#%'
|
||||
-- and a.name not like '%\Administrator'
|
||||
-- and a.name not like '%\UserSQL33'
|
||||
-- and a.name not like 'NT SERVICE\MSSQL%'
|
||||
-- and a.name not like 'NT SERVICE\SQLAgent%'
|
||||
-- and a.name not like 'PL\SSSAISQL%'
|
||||
---- and a.name not like 'PL\sssaa%'
|
||||
-- and a.name not like 'PL\%$'
|
||||
-- and a.name not like 'ELIFE\SQL%'
|
||||
-- and a.name not like 'PLDEV\sss%'
|
||||
---- and 1 in (a.sysadmin, a.securityadmin, a.serveradmin, a.setupadmin, a.processadmin, a.diskadmin, a.dbcreator)
|
||||
|
||||
select rtrim(CONVERT(char(256), SERVERPROPERTY('ComputerNamePhysicalNetBIOS'))) as ServerP, a.name as LoginName,
|
||||
isnull(type_desc, '') as type_desc, isntname, isntgroup, isntuser, isnull(is_disabled, 0) as is_disabled
|
||||
-- , createdate, updatedate, dbname, is_policy_checked, is_expiration_checked
|
||||
, a.sysadmin, a.securityadmin
|
||||
-- , a.serveradmin, a.setupadmin, a.processadmin, a.diskadmin, a.dbcreator, a.bulkadmin
|
||||
from master.sys.sql_logins x right outer join master.sys.syslogins a on x.name = a.name
|
||||
-- select * from master.sys.syslogins
|
||||
--where a.name not in ('sa','sql_sa','NT AUTHORITY\SYSTEM','NT SERVICE\MSSQLSERVER','PL\IBMSQLAdminsPL',
|
||||
-- 'PL\SSSAITMSQLAGT','NT SERVICE\SQLSERVERAGENT','PL\YGAPSDD_SQL','ELIFE\sssITMSQLsrv','ELIFE\sssLogShippingSQL',
|
||||
-- 'ELIFE\ElSrv_Clu','PLDEV\Local IBM SQL Admins','PLDEV\Local SDD SQL','sssLogShippingSQL')
|
||||
-- and a.name not like '#%'
|
||||
-- and a.name not like '%\Administrator'
|
||||
-- and a.name not like '%\UserSQL33'
|
||||
-- and a.name not like 'NT SERVICE\MSSQL%'
|
||||
-- and a.name not like 'NT SERVICE\SQLAgent%'
|
||||
-- and a.name not like 'PL\SSSAISQL%'
|
||||
---- and a.name not like 'PL\sssaa%'
|
||||
-- and a.name not like 'PL\%$'
|
||||
-- and a.name not like 'ELIFE\SQL%'
|
||||
-- and a.name not like 'PLDEV\sss%'
|
||||
---- and 1 in (a.sysadmin, a.securityadmin, a.serveradmin, a.setupadmin, a.processadmin, a.diskadmin, a.dbcreator)
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
|
||||
A Simple script to verify whether your SQL Server is running on a Physical Box or a Virtual machine without RDP'ing into your server.
|
||||
|
||||
Note: This Script works only on 2008R2 SP1 and above..
|
||||
|
||||
*/
|
||||
|
||||
SELECT SERVERPROPERTY('computernamephysicalnetbios') AS ServerName
|
||||
,dosi.virtual_machine_type_desc
|
||||
,Server_type = CASE
|
||||
WHEN dosi.virtual_machine_type = 1
|
||||
THEN 'Virtual'
|
||||
ELSE 'Physical'
|
||||
END
|
||||
FROM sys.dm_os_sys_info dosi
|
||||
|
||||
|
||||
|
||||
/* If you have a CMS configured, run the below Script from your CMS against multiple servers*/
|
||||
|
||||
|
||||
SELECT dosi.virtual_machine_type_desc
|
||||
,Server_type = CASE
|
||||
WHEN dosi.virtual_machine_type = 1
|
||||
THEN 'Virtual'
|
||||
ELSE 'Physical'
|
||||
END
|
||||
FROM sys.dm_os_sys_info dosi
|
||||
@@ -0,0 +1,6 @@
|
||||
-- pokazuje tylko sesje ktore wykonuja zapis do bazy danych
|
||||
SELECT * FROM
|
||||
sys.dm_exec_sessions
|
||||
WHERE is_user_process = 1
|
||||
AND writes > 0;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
select @@servername as ServerName, a.Name as JobName, a.enabled, a.start_step_id, b.message, b.run_status, b.run_date as RunDate,
|
||||
substring(replicate('0', 6 - len(b.run_time)) + cast(b.run_time as varchar), 1, 2) +
|
||||
':' + substring(replicate('0', 6 - len(b.run_time)) + cast(b.run_time as varchar), 3, 2) +
|
||||
':' + substring(replicate('0', 6 - len(b.run_time)) + cast(b.run_time as varchar), 5, 2) as RunTime,
|
||||
substring(replicate('0', 6 - len(b.run_duration)) + cast(b.run_duration as varchar), 1, 2) +
|
||||
':' + substring(replicate('0', 6 - len(b.run_duration)) + cast(b.run_duration as varchar), 3, 2) +
|
||||
':' + substring(replicate('0', 6 - len(b.run_duration)) + cast(b.run_duration as varchar), 5, 2) as DurationSec
|
||||
from msdb..sysjobs a with (nolock)
|
||||
join msdb..sysjobhistory b with (nolock) on a.job_id = b.job_id
|
||||
where run_status not in (1,4)
|
||||
and cast(cast(b.run_date as varchar) as datetime) > getdate() - 3
|
||||
order by run_date desc, run_time desc
|
||||
|
||||
|
||||
select @@servername as ServerName, a.Name as JobName,
|
||||
a.enabled, a.start_step_id,
|
||||
b.message, b.run_status,
|
||||
b.run_date as RunDate,
|
||||
substring(run_time, 1, 2) + ':' + substring(run_time, 3, 2) + ':' + substring(run_time, 5, 2) as RunTime,
|
||||
b.run_duration as DurationSec
|
||||
from msdb..sysjobs a with (nolock)
|
||||
cross apply (
|
||||
select top 15 b.message, b.run_status,
|
||||
cast(b.run_date as varchar) as run_date, replicate('0', 6 - len(b.run_time)) + cast(b.run_time as varchar) as run_time,
|
||||
b.run_duration
|
||||
from msdb..sysjobhistory b with (nolock)
|
||||
where b.step_id = 0
|
||||
and a.job_id = b.job_id
|
||||
order by run_date desc, run_time desc
|
||||
) b
|
||||
where run_status <> 1
|
||||
and cast(cast(b.run_date as varchar) as datetime) > getdate() - 2
|
||||
order by name, run_date desc, run_time desc
|
||||
go
|
||||
|
||||
create table #errorlog(logdate datetime, processinfo varchar(255), info varchar(MAX))
|
||||
|
||||
insert into #errorlog
|
||||
exec xp_readerrorlog
|
||||
|
||||
select * from #errorlog
|
||||
where logdate > getdate() - 2
|
||||
and left(info, 29) <> 'Log was backed up. Database: '
|
||||
and left(info, 20) <> 'Starting up database'
|
||||
and left(info, 28) <> 'Log was restored. Database: '
|
||||
and right(info, 34) <> 'does not allow recovery to be run.'
|
||||
and info <> 'Error: 18456, Severity: 14, State: 8.'
|
||||
and info <> 'Error: 18054, Severity: 16, State: 1.'
|
||||
and LEFT(info, 11) <> 'Error: 6000'
|
||||
and LEFT(info, 3) <> 'IDS'
|
||||
and info <> 'Error: 18452, Severity: 14, State: 1.'
|
||||
and info <> 'Error: 17806, Severity: 20, State: 14.'
|
||||
-- and info like '%request%'
|
||||
|
||||
order by logdate
|
||||
drop table #errorlog
|
||||
@@ -0,0 +1 @@
|
||||
select scheduler_id,cpu_id, status, is_online from sys.dm_os_schedulers where status='VISIBLE ONLINE'
|
||||
Reference in New Issue
Block a user