Skip to content

Instantly share code, notes, and snippets.

@MarshalOfficial
MarshalOfficial / RecoverSuspectDatabase.sql
Created October 21, 2015 12:50
recover suspect database (warning:don't run all lines in one batch script)
EXEC sp_resetstatus 'test_dr';
ALTER DATABASE test_dr SET EMERGENCY
DBCC checkdb('test_dr')
ALTER DATABASE test_dr SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('test_dr', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE test_dr SET MULTI_USER
DBCC CheckDB ('test_dr')
ALTER DATABASE test_dr SET Online
@MarshalOfficial
MarshalOfficial / listchangesvaluebetween2table.sql
Created September 9, 2020 10:46
listchangesvaluebetween2table in sql server
WITH Items
AS (
SELECT 1 AS ID
,CodingDepartment_ID
,CodingBrand_ID
,K_Name
,K_Bar_Code
,K_Desc
,IsActive
,ProviderMainAccount_ID
@MarshalOfficial
MarshalOfficial / missingIndex.sql
Created September 9, 2020 17:06
query giving needed index in mssql server db
DECLARE @minUserImpact INT = 50
DECLARE @minUserSeeks INT = 100
SELECT MIGS.last_user_seek
,MIGS.avg_user_impact
,MIGS.avg_total_user_cost
,MIGS.user_seeks
,MIGS.user_scans
,MIGS.avg_user_impact * MIGS.avg_total_user_cost * (MIGS.user_scans + MIGS.user_seeks) AS Benefit
@MarshalOfficial
MarshalOfficial / colinfo.sql
Created October 5, 2020 10:52
get all tables column information with datatype name
SELECT s.name AS 'schema', ts.name AS TableName,
c.name AS column_name, c.column_id,
SCHEMA_NAME(t.schema_id) AS DatatypeSchema,
t.name AS Datatypename
,t.is_user_defined, t.is_assembly_type
,c.is_nullable, c.max_length, c.PRECISION,
c.scale
FROM sys.columns AS c
INNER JOIN sys.types AS t ON c.user_type_id=t.user_type_id
INNER JOIN sys.tables ts ON ts.OBJECT_ID = c.OBJECT_ID
@MarshalOfficial
MarshalOfficial / config.txt
Created October 20, 2020 19:53
raspberry pi 7 inch monitor config
init_uart_clock=16000000 # set uart clock to 16mhz
kernel_old=1 # load kernel.img at physical memory address 0x0
safe_mode_gpio=8 # a temp firmware limitation workaround
max_usb_current=1 # enable maximum usb current
gpu_mem=32
hdmi_force_hotplug=1 # enable hdmi display even if it is not connected (640x480)
@MarshalOfficial
MarshalOfficial / crossapply.sql
Created November 23, 2020 14:10
call table value function with base table select statement
--The APPLY operator should do the trick:
SELECT *
from MarketDataMaster
cross apply dbo.fn_MarketDataDetails (MarketDataMasterID)
--This essentially calls the function once per row returned from MarketDataMaster. "cross apply" works like an inner join, in that only rows for which data is returned by the function will be returned; use "outer apply" for functionality similar to left outer joins.
@MarshalOfficial
MarshalOfficial / scp.cs
Last active January 5, 2021 07:40
SCP Sample C#, it will copy all the files in target folder to a remote server target location via scp and parallelism with max thread count is manageable
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinSCP;
namespace YOURPROJECTNAMESPACE
@MarshalOfficial
MarshalOfficial / cmd.cs
Created January 5, 2021 07:45
run a cmd command in c#
public static void RunCmd(string command)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "app name like bcp";
proc.StartInfo.Arguments = command;
proc.Start();
proc.WaitForExit();
}
@MarshalOfficial
MarshalOfficial / bcp.cs
Created January 5, 2021 07:46
export sql server data to text file via bcp and parallelism and pagination
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YOURPROJECTNAMESPACE
{
@MarshalOfficial
MarshalOfficial / redis.cs
Created January 5, 2021 07:49
batch insert to redis via MSET in stackexchange.redis c# library
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;