Skip to content

Instantly share code, notes, and snippets.

@nchammas
nchammas / checksum_collisions.sql
Created September 30, 2011 18:33
SQL Server CHECKSUM() Collisions
-- The gist of it:
-- Use HASHBYTES('SHA1', @input); instead of CHECKSUM(@input); if you are interested
-- in using hashes to detect code changes.
-- oops! I deleted too many records
DECLARE @old_proc_definition VARCHAR(MAX) = '
DELETE FROM dbo.transactions
WHERE txn_id < 10000000000000000;
';
@nchammas
nchammas / simple_bank.sql
Created September 9, 2011 22:27
Simple bank schema in T-SQL
-- required SET options for indexed view
SET ANSI_NULLS ON;
SET ANSI_PADDING ON;
SET ANSI_WARNINGS ON;
SET CONCAT_NULL_YIELDS_NULL ON;
SET NUMERIC_ROUNDABORT OFF;
SET QUOTED_IDENTIFIER ON;
SET ARITHABORT ON;
--
@nchammas
nchammas / default_language.sql
Created August 30, 2011 17:48
Recursive T-SQL CTE to find root of arbitrarily deep hierarchy
-- schema
--DROP TABLE dbo.common_Text;
--DROP TABLE dbo.common_LanguageType;
--DROP TABLE dbo.common_Comment;
CREATE TABLE dbo.common_Comment (
CommentId BIGINT NOT NULL PRIMARY KEY
);
CREATE TABLE dbo.common_LanguageType (