Skip to content

Instantly share code, notes, and snippets.

View m4tt1mus's full-sized avatar
💭
I did this with GitHub's GraphQL API

Matt S m4tt1mus

💭
I did this with GitHub's GraphQL API
View GitHub Profile
-- Adapted from Jon Galloway: http://weblogs.asp.net/jgalloway/archive/2006/04/12/442616.aspx
-- This couldn't handle multiple schemas in the same table. Fixed.
-- Removed concat to widen support to earlier versions of MSSQL.
CREATE PROCEDURE [dbo].[sp_drop_constraints]
@database [sysname] = NULL,
@table [sysname],
@verbose [bit] = 0
AS
@m4tt1mus
m4tt1mus / TableKiller.sql
Created August 15, 2014 13:47
Table Killer :)
-- 1. Fill out the DbName.
-- 2. Run Script
-- 3. Select column with scripts
-- 4. Copy to another the column
-- 5. Paste scripts into new scripts screen and execute
DECLARE @Db varchar(100) = 'TechShare-Prosecutor_midland-smoke-test'
SELECT 1, 'USE [' + @Db + ']'
-- Drops unique and foreign key constraints
UNION SELECT 2, 'ALTER TABLE [' + @Db + '].[' + CONSTRAINT_SCHEMA + '].['+ TABLE_NAME
@m4tt1mus
m4tt1mus / ToggleConstraints.sql
Created August 15, 2014 21:06
Toggle constraints
-- turn off constraints on db
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
-- turn on constraints on db
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
@m4tt1mus
m4tt1mus / index.html
Last active August 29, 2015 14:18
Serialize form to JSON.
<html>
<head>
<title>json serialize form</title>
<script src="https://code.jquery.com/jquery-2.1.3.js"></script>
<script type="javascript/text">
$.fn.serializeForm = function () {
var serializedObject = {};
var inputsArray = this.serializeArray();
for (var i = inputsArray.length - 1; i >= 0; i--) {
var input = inputsArray[i];
@m4tt1mus
m4tt1mus / FixieEfExceptions.cs
Created September 2, 2015 15:03
Catch EF Exceptions and report them in fixie
//catch EF Exceptions and report them in fixie
namespace Test.Tests
{
using System;
using System.Data.Entity.Validation;
using Fixie;
public class CustomConvention : Convention
{
@m4tt1mus
m4tt1mus / Stack Usings
Created November 3, 2012 05:47
Stack Usings
using (SqlConnection conn = new SqlConnection(strConn))
using (SqlCommand cmd = new SqlCommand(strQuery, conn))
using (SqlCommand cmdReset = new SqlCommand("DBCC CHECKIDENT('Doctor', RESEED, 0)", conn))
using (SqlCommand cmdUnCheck = new SqlCommand("alter table [dbo].[Doctor] nocheck constraint all",conn))
using (SqlCommand cmdCheck = new SqlCommand("alter table [dbo].[Doctor] with check check constraint all",conn))
{
// do stuff
}