Created
January 23, 2018 21:34
-
-
Save matt40k/590637ed0e8778c9375e13b7a762b80c to your computer and use it in GitHub Desktop.
Code snippet from David Williams @smooth1x1 presentation at the Jan'18 - East Anglia SQL Server User Group - SQL Server 2017 on Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
systemctl status mssql-server | |
runas /netonly /user:WIN-PDNIP9N5COG\justdave “C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe” | |
-- Backup/Restore | |
CREATE DATABASE justdave; | |
BACKUP DATABASE justdave TO DISK = 'C:\x\justdave.bak'; | |
cp /mnt/hgfs/x/justdave.bak /tmp/x/justdave.bak | |
RESTORE DATABASE justdave | |
FROM DISK = '/tmp/x/justdave.bak' | |
WITH RECOVERY, | |
MOVE 'justdave' TO 'C:\var\opt\mssql\data\justdave.mdf', | |
MOVE 'justdave_log' TO 'C:\var\opt\mssql\data\justdave_log.ldf'; | |
-- Compile CLR | |
File->New->Project->SQL Server->Visual C# SQL CLR Database Project. | |
Project->Add New Item->User-Defined Function | |
-- Visual Studio 2015 | |
-- File->New->Project->SQL Server | |
-- Project->Add New Item->SQL CLR C#->SQL CLR# User Defined Function | |
Name DoubleMe | |
Add Code: | |
using System.Data.SqlTypes; | |
using Microsoft.SqlServer.Server; | |
public partial class UserDefinedFunctions | |
{ | |
public const double SALES_TAX = .086; | |
[SqlFunction()] | |
public static SqlDouble DoubleMe(SqlDouble originalAmount) | |
{ | |
SqlDouble doubleAmount = originalAmount * 2; | |
return doubleAmount; | |
} | |
} | |
// Build-> Build Solution -> C:\Users\David\Documents\Visual Studio 2015\Projects\Database2\Database2\bin\Debug | |
//Solution Explorer->TestScripts->Test.sql | |
// Deploy Linux | |
mkdir /var/opt/udr | |
cp /mnt/hgfs/x/Database3.dll /var/opt/udr | |
CREATE ASSEMBLY Database2 FROM 'C:\var\opt\udr\Database3.dll'; | |
CREATE FUNCTION [dbo].[DoubleMe] (@originalAmount as float) | |
RETURNS float | |
AS EXTERNAL NAME [Database3].[UserDefinedFunctions].[DoubleMe]; | |
sp_configure 'clr enabled',1; | |
reconfigure; | |
select dbo.DoubleMe(3) | |
drop function dbo.DoubleMe; | |
drop assembly Database2; | |
// Deploy Windows | |
// Copy Z:\x\Database2.Dll -> C:\x\Database2.DLL | |
CREATE ASSEMBLY Database2 FROM 'C:\x\Database2.dll'; | |
CREATE FUNCTION [dbo].[DoubleMe] (@originalAmount as float) | |
RETURNS float | |
AS EXTERNAL NAME [Database2].[UserDefinedFunctions].[DoubleMe]; | |
sp_configure 'clr enabled',1; | |
reconfigure; | |
select dbo.DoubleMe(3) | |
select * from sys.dm_os_windows_info; | |
select * from sys.dm_os_host_info; | |
select * from sys.dm_os_sys_info; | |
select * from sys.dm_os_sys_memory; | |
select * from sys.dm_linux_proc_all_stat; | |
select * from sys.dm_linux_proc_cpuinfo; | |
select * from sys.dm_linux_proc_meminfo; | |
select * from sys.dm_linux_proc_sql_maps; | |
select * from sys.dm_linux_proc_sql_threads; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment