This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| DB_NAME() AS database_name, | |
| sc.name + N'.' + t.name AS table_name, | |
| (SELECT MAX(user_reads) | |
| FROM (VALUES (last_user_seek), (last_user_scan), (last_user_lookup)) AS value(user_reads)) AS last_user_read, | |
| last_user_update, | |
| CASE si.index_id WHEN 0 THEN N'/* No create statement (Heap) */' | |
| ELSE | |
| CASE is_primary_key WHEN 1 THEN | |
| N'ALTER TABLE ' + QUOTENAME(sc.name) + N'.' + QUOTENAME(t.name) + N' ADD CONSTRAINT ' + QUOTENAME(si.name) + N' PRIMARY KEY ' + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT sdb.Name AS DatabaseName, | |
| COALESCE(CONVERT(VARCHAR(12), MAX(bus.backup_finish_date), 101),'-') AS LastBackUpTime | |
| FROM sys.sysdatabases sdb | |
| LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name | |
| GROUP BY sdb.Name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT DISTINCT vs.volume_mount_point, vs.file_system_type, | |
| vs.logical_volume_name, CONVERT(DECIMAL(18,2),vs.total_bytes/1073741824.0) AS [Total Size (GB)], | |
| CONVERT(DECIMAL(18,2), vs.available_bytes/1073741824.0) AS [Available Size (GB)], | |
| CONVERT(DECIMAL(18,2), vs.available_bytes * 1. / vs.total_bytes * 100.) AS [Space Free %] | |
| FROM sys.master_files AS f WITH (NOLOCK) | |
| CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.[file_id]) AS vs | |
| ORDER BY vs.volume_mount_point OPTION (RECOMPILE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @filename NVARCHAR(1000); | |
| DECLARE @bc INT; | |
| DECLARE @ec INT; | |
| DECLARE @bfn VARCHAR(1000); | |
| DECLARE @efn VARCHAR(10); | |
| -- Get the name of the current default trace | |
| SELECT @filename = CAST(value AS NVARCHAR(1000)) | |
| FROM ::fn_trace_getinfo(DEFAULT) | |
| WHERE traceid = 1 AND property = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT command, | |
| s.text, | |
| start_time, | |
| percent_complete, | |
| CAST(((DATEDIFF(s,start_time,GetDate()))/3600) as varchar) + ' hour(s), ' | |
| + CAST((DATEDIFF(s,start_time,GetDate())%3600)/60 as varchar) + 'min, ' | |
| + CAST((DATEDIFF(s,start_time,GetDate())%60) as varchar) + ' sec' as running_time, | |
| CAST((estimated_completion_time/3600000) as varchar) + ' hour(s), ' | |
| + CAST((estimated_completion_time %3600000)/60000 as varchar) + 'min, ' | |
| + CAST((estimated_completion_time %60000)/1000 as varchar) + ' sec' as est_time_to_go, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- show fragmentation for heaps in database | |
| SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | |
| GO | |
| IF OBJECT_ID('tempdb..#HeapDetails') IS NOT NULL | |
| DROP TABLE #HeapDetails; | |
| CREATE TABLE #HeapDetails ( | |
| ObjectName SYSNAME, | |
| PageCount INT, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT DISTINCT vs.volume_mount_point, vs.file_system_type, | |
| vs.logical_volume_name, CONVERT(DECIMAL(18,2),vs.total_bytes/1073741824.0) AS [Total Size (GB)], | |
| CONVERT(DECIMAL(18,2), vs.available_bytes/1073741824.0) AS [Available Size (GB)], | |
| CONVERT(DECIMAL(18,2), vs.available_bytes * 1. / vs.total_bytes * 100.) AS [Space Free %] | |
| FROM sys.master_files AS f WITH (NOLOCK) | |
| CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.[file_id]) AS vs | |
| ORDER BY vs.volume_mount_point OPTION (RECOMPILE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @filename NVARCHAR(1000); | |
| DECLARE @bc INT; | |
| DECLARE @ec INT; | |
| DECLARE @bfn VARCHAR(1000); | |
| DECLARE @efn VARCHAR(10); | |
| -- Get the name of the current default trace | |
| SELECT @filename = CAST(value AS NVARCHAR(1000)) | |
| FROM ::fn_trace_getinfo(DEFAULT) | |
| WHERE traceid = 1 AND property = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| USE [msdb] | |
| GO | |
| EXEC master.dbo.sp_MSsetalertinfo @failsafeoperator=N'YourOperator', | |
| @notificationmethod=1 | |
| GO | |
| USE [msdb] | |
| GO | |
| EXEC msdb.dbo.sp_set_sqlagent_properties @email_save_in_sent_folder=1 | |
| GO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Create a test database. | |
| CREATE DATABASE myDatabase | |
| --Change database context. | |
| USE myDatabase | |
| GO | |
| --Create a test table. | |
| CREATE TABLE myTable ( firstname VARCHAR(50), surname VARCHAR(50), email VARCHAR(255) ) |
OlderNewer