-- Recursive SQL
WITH t(n) AS (
SELECT 1
UNION ALL
SELECT n+1 FROM t WHERE n< 5
)
SELECT n
FROM t
-- Data Generation with Recursive SQL
WITH
t1(v1, v2) AS (SELECT 1, 2),
t2(w1, w2) AS (
SELECT v1 * 2, v2 * 2
FROM t1
)
SELECT *
FROM t1, t2
“No problem can be solved from the same level of consciousness that created it.” Albert Einstein (1879-1955)
Tuesday, 4 May 2021
SQL Recursion
Thursday, 4 March 2021
Detect SQL Database Changes using C# Table Dependency and SQL Broker
using System;
using TableDependency.SqlClient;
using TableDependency.SqlClient.Base;
using TableDependency.SqlClient.Base.Enums;
using TableDependency.SqlClient.Base.EventArgs;
namespace SQLCDC
{
class
Program
{
static
void Main(string[] args)
{
string
connectionString = "Server=localhost;Database=Test;Integrated
Security=True;";
var
mapper = new ModelToTableMapper<People>();
mapper.AddMapping(c
=> c.name, "Name");
mapper.AddMapping(c
=> c.age, "Age");
using
(var dep = new SqlTableDependency<People>(connectionString,
"People", mapper: mapper))
{
dep.OnChanged
+= Changed;
dep.Start();
Console.ReadKey();
dep.Stop();
}
}
public
static void Changed(object sender, RecordChangedEventArgs<People> e)
{
var
changedEntity = e.Entity;
if
(e.ChangeType != ChangeType.None)
{
switch
(e.ChangeType)
{
case
ChangeType.Delete:
break;
case
ChangeType.Update:
break;
case
ChangeType.Insert:
break;
case
ChangeType.None:
Console.WriteLine("None");
break;
}
}
Console.WriteLine("DML
OPR: " + e.ChangeType);
Console.WriteLine(" Name: " + changedEntity.name);
Console.WriteLine(" Age: " + changedEntity.age);
Console.WriteLine();
}
}
public
class People
{
public
string name { get; set; }
public
string age { get; set; }
}
}
/*
use
master
select
is_broker_enabled from sys.databases where name= 'Test'
use
test
go
create
table people (
id
int identity (1,1) not null,
name
varchar(50) not null,
age
nchar(10),
primary
key (id)
)
select
* from people
insert
into people (name, age) values ('A', 45)
insert
into people (name, age) values ('B', 50)
insert
into people (name, age) values ('C', 23)
select
* from people
update
people set name='A1' where name='A'
--
truncate table people
*/
Read more...
Friday, 18 December 2020
Export data from stored procedure to CSV
-- xp_cmdshell must be enabled under server security
DECLARE @cmd as varchar(4000) = 'BCP "Exec BikeStores.dbo.Test" QUERYOUT "D:\1.csv" -c -t\^, -T -S' + @@servername
EXEC master..xp_cmdshell @cmd
Monday, 5 October 2020
Friday, 4 September 2020
Powerwashing the Chromebook
- Sign out of your Chromebook
- Press and hold Ctrl + Alt + Shift + r
- Select Restart
- In the box that appears, select Powerwash. Continue
- Follow the steps that appear and sign in with your Google Account
Sunday, 31 May 2020
VMWare Cannot Join to Domain - Domain in Unreachable
1. Open cmd as an administrator
2. Execute the following command: bcdedit /set hypervisorlaunchtype off
3. Restart the host
4. Executing the following command should display the domain names: resolve-dnsname <domain-name>
Saturday, 30 May 2020
Building a Windows Server Core from a Full GUI Install
- Reduced attack surface
- Reduced maintenance
- Consume fewer hardware resources
- Increased stability due to fewer running applications
- Clean install a full Windows Server
- Open Powershell as Administrator
- Execute the following commands:
Import-Module ServerManager
Uninstall-WindowsFeature Server-Gui-Shell-Restart
Uninstall-WindowsfeatureServer-Gui-Mgmt-Infra-Restart
Powershell C:\>sconfig.cmd # configure the server
Create modal using HTML and CSS
<body> <dialog id = "modal"> <div> <h1>Title</h1> <p>Sample Text</p...
-
<asp:UpdatePanel runat="server"> <ContentTemplate> Employee : <asp:ListBox ID="lstEmployee" r...
-
//convert BASE64 string to Byte{} array function base64ToArrayBuffer(base64) { var binaryString = window.atob(base64); var binar...
-
# Run PowerShell as Administrator Install-Module -Name UniversalDashboard.Community # Check PowerShellGet version Get-Module -Name PowerShel...