Skip to content

Instantly share code, notes, and snippets.

View tables-row-count.sql
CREATE TABLE #counts
(
table_name varchar(255),
row_count int
)
EXEC sp_MSForEachTable @command1=
'INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ?'
SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC
DROP TABLE #counts
View Workaround_index.html
<html>
<head>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript">
$.ajaxSetup ({
cache: false // Disable caching of AJAX responses
});
$(document).ready(function() {
View SQL_Bulk_switch_DBs_from_read_only_to_RW.sql
SELECT CONCAT('ALTER DATABASE [', name, '] SET READ_WRITE WITH NO_WAIT')
FROM sys.databases where is_read_only=1;
View Attach_K2_DBs.sql
IF NOT EXISTS (SELECT TOP 1 1 FROM sys.databases WHERE name = 'K2Categories')
BEGIN
CREATE DATABASE [K2Categories] ON
(FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\K2Categories.mdf')
, (FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\K2Categories_log.LDF')
FOR ATTACH;
END
GO
IF NOT EXISTS (SELECT TOP 1 1 FROM sys.databases WHERE name = 'K2Dependencies')
View K2DBs_collation_check.sql
SELECT D.name AS DatabaseName
, D.collation_name
FROM sys.databases AS D
WHERE D.Name like 'K2%'
View SQL_Server_collation_check.sql
SELECT CONVERT (varchar, SERVERPROPERTY('collation')) as 'SQL Server Collation';
View Start_K2_setup_DB_connection.sql
$newConnection = "Data Source=DLX;Initial Catalog=K2;Integrated Security=True"
$installKey = Get-ItemProperty "HKLM:\SOFTWARE\SourceCode\blackpearl\blackpearl Core"
$configPath = $installKey.InstallDir + "Setup\Configuration.config"
$xml = New-Object XML
$xml.Load($configPath)
$connectionNode = $xml.configuration.configurationdatabase.add | Where-Object { $_.key -eq 'connectionString' }
$connectionNode.value = $newConnection
View Enable_TDE.sql
USE master;
GO
IF (select Count(*) from sys.symmetric_keys where name like '%DatabaseMasterKey%') = 0
BEGIN
CREATE MASTER KEY ENCRYPTION BY PASSWORD='P@ssw0rd';
END
GO
IF (select Count(*) from sys.certificates where name = 'TdeCertificate') = 0
BEGIN
CREATE CERTIFICATE TdeCertificate WITH SUBJECT='TDE Certificate'
View Check_TDE_status.sql
--Be sure to select master DB and click "New Query" before runnig this
SELECT [name], is_master_key_encrypted_by_server, is_encrypted
FROM master.sys.databases
GO
--View the symmetric keys
SELECT
[name]
, [principal_id]
You can’t perform that action at this time.