-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added various scrips to the repo for the first official commit
- Loading branch information
Bonza Owl
committed
Dec 1, 2018
1 parent
d0b9953
commit a22ae62
Showing
9 changed files
with
403 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
SELECT | ||
ar.replica_server_name, | ||
adc.database_name, | ||
ag.name AS ag_name, | ||
drs.is_local, | ||
drs.is_primary_replica, | ||
drs.synchronization_state_desc, | ||
drs.is_commit_participant, | ||
drs.synchronization_health_desc, | ||
drs.recovery_lsn, | ||
drs.truncation_lsn, | ||
drs.last_sent_lsn, | ||
drs.last_sent_time, | ||
drs.last_received_lsn, | ||
drs.last_received_time, | ||
drs.last_hardened_lsn, | ||
drs.last_hardened_time, | ||
drs.last_redone_lsn, | ||
drs.last_redone_time, | ||
drs.log_send_queue_size, | ||
drs.log_send_rate, | ||
drs.redo_queue_size, | ||
drs.redo_rate, | ||
drs.filestream_send_rate, | ||
drs.end_of_log_lsn, | ||
drs.last_commit_lsn, | ||
drs.last_commit_time | ||
FROM sys.dm_hadr_database_replica_states AS drs | ||
INNER JOIN sys.availability_databases_cluster AS adc | ||
ON drs.group_id = adc.group_id AND | ||
drs.group_database_id = adc.group_database_id | ||
INNER JOIN sys.availability_groups AS ag | ||
ON ag.group_id = drs.group_id | ||
INNER JOIN sys.availability_replicas AS ar | ||
ON drs.group_id = ar.group_id AND | ||
drs.replica_id = ar.replica_id | ||
ORDER BY | ||
ag.name, | ||
ar.replica_server_name, | ||
adc.database_name; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
USE [master] | ||
GO | ||
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultData', REG_SZ, N'D:' | ||
GO | ||
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultLog', REG_SZ, N'L:' | ||
GO |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
DECLARE @ClarionDate INT = 76734 | ||
DECLARE @SqlDateTime DATETIME | ||
|
||
-- Convert the clarion DATE into and SQL DateTime | ||
SET @SqlDateTime = DateAdd(day, @ClarionDate - 4, '1801-01-01') | ||
|
||
SELECT @SqlDateTime AS 'SQL Date Time' | ||
|
||
-- Now convert it back from and SQL DateTime to a Clarion Date | ||
SET @ClarionDate = DateDiff(day, DateAdd(day, -4, '1801-01-01'), @SqlDateTime) | ||
SELECT @ClarionDate AS 'Clarion Date' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- ============================================= | ||
-- Origional Author: Cody Konior (codykonior.com) | ||
-- Editing Author: Bonza Owl | ||
-- Create date: 28/09/2018 | ||
-- ============================================= | ||
|
||
CREATE PROCEDURE p_db_mail_check | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON; | ||
SET XACT_ABORT, | ||
QUOTED_IDENTIFIER, | ||
ANSI_NULLS, | ||
ANSI_PADDING, | ||
ANSI_WARNINGS, | ||
ARITHABORT, | ||
CONCAT_NULL_YIELDS_NULL ON; | ||
SET NUMERIC_ROUNDABORT OFF; | ||
|
||
DECLARE @localTran bit | ||
IF @@TRANCOUNT = 0 | ||
BEGIN | ||
SET @localTran = 1 | ||
BEGIN TRANSACTION LocalTran | ||
END | ||
|
||
BEGIN TRY | ||
|
||
DECLARE | ||
@State TABLE (State varchar(100)) | ||
|
||
INSERT INTO @State | ||
EXEC msdb.dbo.sysmail_help_status_sp | ||
|
||
SELECT | ||
State | ||
FROM | ||
@State | ||
WHERE | ||
State = 'Started' | ||
|
||
IF @@ROWCOUNT = 0 | ||
|
||
BEGIN | ||
EXEC msdb.dbo.sysmail_start_sp | ||
END | ||
|
||
IF @localTran = 1 AND XACT_STATE() = 1 | ||
COMMIT TRAN LocalTran | ||
|
||
END TRY | ||
BEGIN CATCH | ||
|
||
DECLARE @ErrorMessage NVARCHAR(4000) | ||
DECLARE @ErrorSeverity INT | ||
DECLARE @ErrorState INT | ||
|
||
SELECT @ErrorMessage = ERROR_MESSAGE(), | ||
@ErrorSeverity = ERROR_SEVERITY(), | ||
@ErrorState = ERROR_STATE() | ||
|
||
IF @localTran = 1 AND XACT_STATE() <> 0 | ||
ROLLBACK TRAN | ||
|
||
RAISERROR ( @ErrorMessage, @ErrorSeverity, @ErrorState) | ||
|
||
END CATCH | ||
|
||
END |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/****************************** | ||
** Name: SQL Dates | ||
** Desc: A compilation of various date functions for SQL Server | ||
** Auth: Bonza Owl | ||
** Date: 28/11/2018 | ||
*******************************/ | ||
|
||
--FirstDayOfCurrentWeek | ||
SELECT CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0)) AS [FirstDayOfCurrentWeek] | ||
--LastDayOfCurrentWeek | ||
SELECT CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 6)) AS [LastDayOfCurrentWeek] | ||
--FirstDayOfLastWeek | ||
SELECT CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 7, GETDATE()), 0)) AS [FirstDayOfPeviousWeek] | ||
--LastDayOfLastWeek | ||
SELECT CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 7, GETDATE()), 6)) AS [LastDayOfPreviousWeek] | ||
--FirstDayOfNextWeek | ||
SELECT CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 7)) AS [FirstDayOfNextWeek] | ||
--LastDayOfNextWeek | ||
SELECT CONVERT(DATE, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 13)) AS [LastDayOfNextWeek] | ||
--FirstDayOfCurrentMonth | ||
SELECT CONVERT(DATE, DATEADD(d, -( DAY(GETDATE() - 1) ), GETDATE())) AS [FirstDayOfCurrentMonth] | ||
--LastDayOfCurrentMonth | ||
SELECT CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 1, GETDATE())) ), DATEADD(m, 1, GETDATE()))) AS [LastDayOfCurrentMonth] | ||
--FirstDayOfLastMonth | ||
SELECT CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, -1, GETDATE() - 2)) ), DATEADD(m, -1, GETDATE() - 1))) AS [FirstDayOfPreviousMonth] | ||
--LastDayOfLastMonth | ||
SELECT CONVERT(DATE, DATEADD(d, -( DAY(GETDATE()) ), GETDATE())) AS [LastDayOfPreviousMonth] | ||
--FirstDayOfNextMonth | ||
SELECT CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 1, GETDATE() - 1)) ), DATEADD(m, 1, GETDATE()))) AS [FirstDayOfNextMonth] | ||
--LastDayOfNextMonth | ||
SELECT CONVERT(DATE, DATEADD(d, -( DAY(DATEADD(m, 2, GETDATE())) ), DATEADD(m, 2, GETDATE()))) AS [LastDayOfNextMonth] | ||
--FirstDayOfCurrentYear | ||
SELECT CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0)) AS [FirstDayOfCurrentYear] | ||
--LastDayOfCurrentYear | ||
SELECT CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0)))) AS [LastDayOfCurrentYear] | ||
--FirstDayOfLastYear | ||
SELECT CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) - 1, 0)) AS [FistDayOfLastYear] | ||
--LastDayOfLastYear | ||
SELECT CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0)))) AS [LastDayOfPreviousYear] | ||
--FirstDayOfNextYear | ||
SELECT CONVERT(DATE, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0)) AS [FirstDayOfPreviousYear] | ||
--LastDayOfNextYear | ||
SELECT CONVERT(DATE, DATEADD(ms, -2, DATEADD(YEAR, 0, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 2, 0)))) AS [LastDayOfNextYear] | ||
--CurrentYear | ||
SELECT DATEPART(year,GETDATE()) AS [CurrentYear] | ||
--CurrentMonth | ||
SELECT DATEPART(month,GETDATE()) AS [CurrentMonth] | ||
--CurrentWeekNumber | ||
SELECT DATEPART(wk,GETDATE()) AS [CurrentWeekNumber] | ||
--CurrentDayInMonth | ||
SELECT DATEPART(day,GETDATE()) CurrentDay | ||
--GetWeekDayName | ||
SELECT DATENAME(weekday,GETDATE()) AS WeekdayName | ||
--GetWeekDay | ||
SELECT DATEPART(weekday,GETDATE()) AS WeekdayNumber | ||
--Date30DaysAgo | ||
SELECT DATEADD(day,-30,GETDATE()) AS Date30DaysAgo | ||
--Date30DaysFuture | ||
SELECT DATEADD(day,+30, GETDATE()) AS Date30DaysFuture |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
EXEC sp_configure 'backup compression default', 1 ; | ||
RECONFIGURE WITH OVERRIDE ; | ||
GO | ||
|
||
SELECT value | ||
FROM sys.configurations | ||
WHERE name = 'backup compression default' ; | ||
GO |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--Find the location of the files currently | ||
|
||
SELECT name, physical_name AS current_file_location | ||
FROM sys.master_files | ||
|
||
--Move this for all files for the database, mdf, ldf & ndf files | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='tempdev', | ||
filename='D:\tempdb.mdf' | ||
); --Filename is new location | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='temp2', | ||
filename='D:\tempdb_mssql_2.ndf' | ||
); --Filename is new location | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='temp3', | ||
filename='D:\tempdb_mssql_3.ndf' | ||
); --Filename is new location | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='temp4', | ||
filename='D:\tempdb_mssql_4.ndf' | ||
); --Filename is new location | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='temp5', | ||
filename='D:\tempdb_mssql_5.ndf' | ||
); --Filename is new location | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='temp6', | ||
filename='D:\tempdb_mssql_6.ndf' | ||
); --Filename is new location | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='temp7', | ||
filename='D:\tempdb_mssql_7.ndf' | ||
); --Filename is new location | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='temp8', | ||
filename='D:\tempdb_mssql_8.ndf' | ||
); --Filename is new location | ||
|
||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [tempdb] | ||
MODIFY FILE | ||
( | ||
name='templog', | ||
filename='L:\templog_log.ldf' | ||
); --Filename is new location | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
SELECT name, physical_name | ||
FROM sys.master_files | ||
WHERE database_id = DB_ID(N'model'); | ||
GO | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [msdb] | ||
MODIFY FILE | ||
( | ||
name='MSDBData', | ||
filename='S:\MSDBData.mdf' | ||
); --Filename is new location | ||
|
||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [msdb] | ||
MODIFY FILE | ||
( | ||
name='MSDBLog', | ||
filename='S:\MSDBLog.ldf' | ||
); --Filename is new location | ||
|
||
|
||
/*** MOVE MODEL **/ | ||
|
||
SELECT name, physical_name | ||
FROM sys.master_files | ||
WHERE database_id = DB_ID(N'model'); | ||
GO | ||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [model] | ||
MODIFY FILE | ||
( | ||
name='modeldev', | ||
filename='S:\model.mdf' | ||
); --Filename is new location | ||
|
||
|
||
USE master; --do this all from the master | ||
ALTER DATABASE [model] | ||
MODIFY FILE | ||
( | ||
name='modellog', | ||
filename='S:\modellog.ldf' | ||
); --Filename is new location |
Oops, something went wrong.