Skip to content

Instantly share code, notes, and snippets.

@PeterLehmann
PeterLehmann / index_used_mssql.sql
Last active June 3, 2021 08:15
index used per table
SELECT
s.name AS Schema_Name,
objects.name AS Table_name,
indexes.name AS Index_name,
dm_db_index_usage_stats.user_seeks,
dm_db_index_usage_stats.user_scans,
dm_db_index_usage_stats.user_updates,
dm_db_index_usage_stats.last_user_seek,
dm_db_index_usage_stats.last_user_scan,
dm_db_index_usage_stats.last_user_update
@PeterLehmann
PeterLehmann / missing_index_sql_server.sql
Created December 2, 2019 11:00
mssql missing index
SELECT
dm_mid.database_id AS DatabaseID,
dm_migs.avg_user_impact*(dm_migs.user_seeks+dm_migs.user_scans) Avg_Estimated_Impact,
dm_migs.last_user_seek AS Last_User_Seek,
OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) AS [TableName],
'CREATE INDEX [IX_' + OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) + '_'
+ REPLACE(REPLACE(REPLACE(ISNULL(dm_mid.equality_columns,''),', ','_'),'[',''),']','') +
CASE
WHEN dm_mid.equality_columns IS NOT NULL AND dm_mid.inequality_columns IS NOT NULL THEN '_'
ELSE ''

Keybase proof

I hereby claim:

  • I am peterlehmann on github.
  • I am peterlehmann (https://keybase.io/peterlehmann) on keybase.
  • I have a public key ASC9xorkhkYYKT2UezLQYq0gz7xjAzEaQfsmWPY9yoiS3Ao

To claim this, I am signing this object:

# EditorConfig is awesome:
# http://EditorConfig.org
# top-most EditorConfig file
root = true
# Default settings:
# A newline ending every file
# Use 4 spaces as indentation
# Trim trailing whitespace
[*]
insert_final_newline = true
begin tran;
declare @temp table(ItemLocalInventoryAdjustmentId uniqueidentifier
, ItemLocalId uniqueidentifier
, ReferenceId uniqueidentifier
, ReferenceDetailId uniqueidentifier
, ReferenceTypeId uniqueidentifier
, AdjustmentQty int
, LocallyCreatedBy varchar(5)
, CreatedDateTime datetime
, CreatedBy varchar(10)
#!/bin/sh
ORIG_MSG_FILE="$1"
TEMP="/tmp/git-$RANDOM"
ISSUENUMBER=`git branch | grep '^\*' | cut -f 2 -d ' '| grep -i -E 'LBF' | cut -f 2 -d '/'`
if [ -n "$ISSUENUMBER" ]; then
(echo "issue: $ISSUENUMBER ";cat $ORIG_MSG_FILE) > "$TEMP"
cat "$TEMP" > $ORIG_MSG_FILE
fi
with cte
as
(select ru.RetailUnitNo
, ic.InventoryCountingDate
, i.ItemNo
, icd.StartInventoryQty
, icd.CountedQty
, 'optælling' as type
from trio..RetailUnit ru
inner join trio..InventoryCounting ic on ru.RetailUnitId = ic.RetailUnitId
@PeterLehmann
PeterLehmann / .gitattributes
Created January 6, 2014 12:00
git attributes sample file
*.cs text eol=crlf diff=csharp
*.csproj text eol=crlf merge=union
*.sln text eol=crlf merge=union
*.config text eol=crlf
*.resx text eol=crlf merge=union
* text=auto eol=crlf
*.sh text=auto eol=lf
*.exe binary
*.dll binary
*.DLL binary
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading;
using System.Transactions;
using Coop.Common;
using Coop.Core.Domain.Entities;
using Coop.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading;
using System.Transactions;
using NHibernate;
using NUnit.Framework;
using IsolationLevel = System.Transactions.IsolationLevel;