Skip to content

Instantly share code, notes, and snippets.

View bartread's full-sized avatar
🤢
Balls

Bart Read bartread

🤢
Balls
View GitHub Profile
@bartread
bartread / SimpleSavePocoEntities.cs
Last active November 2, 2015 16:59
POCO entity definitions for simplified user schema
using System;
using System.Collections.Generic;
namespace SimpleSavePocoEntities
{
public class UserDao
{
public int UserKey { get; set; }
public Guid UserGuid { get; set; }
public int EmployeeId { get; set; }
@bartread
bartread / LICENSE.txt
Last active June 4, 2016 10:50
Playing sound effects and music in games at https://arcade.ly - notably Star Citadel, which is available at http://starcas.tl
MIT License
Copyright (c) 2015, 2016 Bart Read, arcade.ly (https://arcade.ly), and
bartread.com Ltd (http://www.bartread.com/)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
@bartread
bartread / createParticle.js
Created July 1, 2016 14:00
Here's my original createParticle() function, showing the wasteful creation of objects every time a particle is created
function createParticle(
definitionName,
position,
velocity) {
var definition = descriptors[definitionName];
if (definition === undefined) {
return undefined;
}
var particle = {
@bartread
bartread / queryiostats.sql
Created January 4, 2017 06:55
Enable/disable IO stats for t-SQL query execution
SET STATISTICS IO ON;
GO
SELECT blah ...
GO
SET STATISTICS IO OFF;
GO
@bartread
bartread / querytimestats.sql
Created January 4, 2017 06:57
Enable/disable CPU and elapsed time stats for t-SQL query execution
SET STATISTICS TIME ON;
GO
SELECT blah ...
GO
SET STATISTICS TIME OFF;
GO
@bartread
bartread / mostexpensiveiocpuqueries.sql
Last active January 26, 2017 10:31
Get most expensive t-SQL queries in terms of I/O or CPU usage
USE [YOUR_DATABASE_NAME]; -- Substitute for your database name
GO
SELECT TOP 10
t.text ,
execution_count ,
statement_start_offset AS stmt_start_offset ,
s.sql_handle ,
s.plan_handle ,
s.total_worker_time / 1000 AS total_cpu_time_millis,
@bartread
bartread / getexecutionplanforhandle.sql
Created January 4, 2017 07:42
Get XML execution plan for plan handle
USE master;
GO
SELECT * FROM sys.dm_exec_query_plan (YOUR_PLAN_HANDLE_HERE);
GO
@bartread
bartread / gettopexecutionplansbycputime.sql
Created January 4, 2017 07:43
Get execution plans for top SQL queries by CPU time
SELECT TOP 5 total_worker_time/execution_count AS [Avg CPU Time],
Plan_handle, query_plan
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
ORDER BY total_worker_time/execution_count DESC;
GO
@bartread
bartread / getmostusedtables.sql
Created January 4, 2017 07:47
Get most used tables in SQL Server
--get most used tables
SELECT
db_name(ius.database_id) AS DatabaseName,
t.NAME AS TableName,
SUM(ius.user_seeks + ius.user_scans + ius.user_lookups) AS NbrTimesAccessed
FROM sys.dm_db_index_usage_stats ius
INNER JOIN sys.tables t ON t.OBJECT_ID = ius.object_id
WHERE database_id = DB_ID('YOUR_DATABASE_HERE')
GROUP BY database_id, t.name
ORDER BY SUM(ius.user_seeks + ius.user_scans + ius.user_lookups) DESC
@bartread
bartread / alternativegetmostusedindexesthatidontlove.sql
Last active May 15, 2024 17:29
Get most used indexes in SQL Server
declare @dbid int
–To get Datbase ID
set @dbid = db_id()
select
db_name(d.database_id) database_name
,object_name(d.object_id) object_name
,s.name index_name,
c.index_columns
,d.*