Skip to content

Instantly share code, notes, and snippets.

View JerryNixon's full-sized avatar
🤔
Trying to make a living.

Jerry Nixon JerryNixon

🤔
Trying to make a living.
View GitHub Profile
@JerryNixon
JerryNixon / InMemTable.sql
Created February 22, 2023 20:31
Create Azure SQL DB In-Memory Table
-- configure recommended DB option
ALTER DATABASE CURRENT SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT=ON;
GO
-- validate tier
IF (DatabasePropertyEx(DB_Name(), 'IsXTPSupported') = 0)
BEGIN
PRINT 'This database does not support in-mem database.'
@JerryNixon
JerryNixon / Menu.cs
Created February 9, 2023 17:31
Week 04 Coding in Class Snapshot
public static class Menu
{
/// <summary>
/// Displays a menu of options on the console and waits for the user to make a selection.
/// </summary>
/// <param name="x">The x-coordinate of the top-left corner of the menu box.</param>
/// <param name="y">The y-coordinate of the top-left corner of the menu box.</param>
/// <param name="items">The options to display in the menu.</param>
/// <returns>The selected option as a string.</returns>
public static void Draw(int x, int y, string current, string[] items)
@JerryNixon
JerryNixon / ColumnstoreParitioning.sql
Created February 3, 2023 01:21
Columnstore & Horizontal Partitioning SQL Server Tables
CREATE PARTITION FUNCTION year_partition_function (varchar(4)) AS
RANGE FOR VALUES ('2019', '2020', '2021')
GO
CREATE PARTITION SCHEME year_partition_scheme AS
PARTITION year_partition_function ALL TO ([PRIMARY])
GO
CREATE TABLE users
(
@JerryNixon
JerryNixon / SqlBulkInsert.cs
Created January 25, 2023 19:35
Inserting as fast as I can.
using System.Data;
using System.Data.SqlClient;
internal class Program
{
static int threads = 0;
static int records = 0;
static int batch = 10_000;
static DateTime started = DateTime.Now;
@JerryNixon
JerryNixon / json.sql
Last active December 14, 2022 01:09
SQL JSON WORK
SET NOCOUNT ON
DECLARE @json NVARCHAR(MAX) =
'{
"reading": {
"source": "A01",
"values": [
{ "date": "2022-12-12", "value": 123.456 }
, { "date": "2022-12-13", "value": 234.567 }
]
@JerryNixon
JerryNixon / FileReadShowdown.cs
Last active December 7, 2022 17:02
Evaluate the performance of DynamicObject versus normal programming.
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Xml.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
@JerryNixon
JerryNixon / part-view.ipynb
Created November 10, 2022 21:58
Creating a partitioned view in SQL Server that auto-partitions INSERT & UPDATE statements
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JerryNixon
JerryNixon / ssn_sex_generator.sql
Last active September 26, 2022 19:56
Generate Social Security Numbers in TSQL
DROP TABLE IF EXISTS #SSN
CREATE TABLE #SSN (
ID INT IDENTITY(1, 1) PRIMARY KEY
, SSN VARCHAR(11) MASKED WITH (FUNCTION = 'partial(0, "XXX-XX-", 4)')
, SEX BIT
, BIRTH INT
)
GO
@JerryNixon
JerryNixon / EntityFramework.cs
Created September 20, 2022 18:52
Generic Repository using Entity Framework
using Library.Models;
using Library.EF;
namespace Abstractions
{
public interface IKeyedModel
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
}
@JerryNixon
JerryNixon / generate.sql
Last active September 10, 2022 01:41
Generate an arbitrary range in T-SQL UDF.
DBCC DROPCLEANBUFFERS;
CHECKPOINT;
DBCC FREEPROCCACHE WITH no_infomsgs;
GO
CREATE OR ALTER FUNCTION Range (@start BIGINT, @end BIGINT)
RETURNS @table TABLE (Id BIGINT) AS
BEGIN
-- Jerry Nixon