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
--compress all uncompressed tables and indexes in a SQL SERVER 2017 or later database | |
--modify the dabase name below | |
USE XXDATABASE_NAMEXX; | |
DECLARE @sqltext NVARCHAR(MAX) | |
SET @sqltext = N'USE ' + DB_NAME() + N';' + NCHAR(13) + NCHAR(10) | |
SELECT @sqltext = @sqltext + N'ALTER ' + CASE | |
WHEN p.index_id IN (0,1) |
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
/* Microsoft T-SQL, tested on SQL Server 2014 */ | |
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | |
USE tempdb; | |
/*********** CREATE TEST DATA ***********/ | |
/* temporary table for testing with sample calculated metric, could be the result of a WITH common table expression or subquery instead*/ | |
CREATE TABLE #mymetricdata ( | |
key_field INT IDENTITY PRIMARY KEY CLUSTERED | |
,metric FLOAT |
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
IF EXISTS ( | |
SELECT * | |
FROM sys.objects | |
WHERE object_id = OBJECT_ID(N'[dbo].[base32enc]') | |
AND type IN ( | |
N'FN' | |
,N'IF' | |
,N'TF' | |
,N'FS' | |
,N'FT' |
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
CREATE FUNCTION dbo.HMAC ( | |
@algo VARCHAR(20) | |
,@key VARBINARY(MAX) | |
,@data VARBINARY(MAX) | |
) | |
/* This function only takes VARBINARY parameters instead of VARCHAR | |
to prevent problems with implicit conversion from NVARCHAR to VARCHAR | |
which result in incorrect hashes for inputs including non-ASCII characters. | |
Always cast @key and @data parameters to VARBINARY when using this function. | |
Tested against HMAC vectors for MD5 and SHA1 from RFC 2202 */ |