Merge branch 'microsoft:master' into master

This commit is contained in:
Pieter Vanhove
2022-03-04 08:37:05 +01:00
committed by GitHub
34 changed files with 3604 additions and 1283 deletions
@@ -84,7 +84,7 @@ param(
$col2 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "InstanceName", [Microsoft.SqlServer.Management.Smo.DataType]::VarChar(50))
$col3 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "Status", [Microsoft.SqlServer.Management.Smo.DataType]::VarChar(30))
$col4 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "Name", [Microsoft.SqlServer.Management.Smo.DataType]::VarChar(255))
$col5 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "SizeMB", [Microsoft.SqlServer.Management.Smo.DataType]::VarChar(30))
$col5 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "SizeMB", [Microsoft.SqlServer.Management.Smo.DataType]::Decimal(6, 38))
$col6 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "SourceCompatibilityLevel", [Microsoft.SqlServer.Management.Smo.DataType]::VarChar(15))
$col7 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "TargetCompatibilityLevel", [Microsoft.SqlServer.Management.Smo.DataType]::VarChar(15))
$col8 = New-Object Microsoft.SqlServer.Management.Smo.Column($ReportDatatbl, "Category", [Microsoft.SqlServer.Management.Smo.DataType]::VarChar(30))
@@ -726,7 +726,7 @@ INSERT INTO BreakingChangeWeighting VALUES ('Microsoft.Rules.Data.Upgrade.UR0000
$datatable.columns.add("InstanceName",[String]) | Out-Null
$datatable.columns.add("Status",[String]) | Out-Null
$datatable.columns.add("Name",[String]) | Out-Null
$datatable.columns.add("SizeMB",[String]) | Out-Null
$datatable.columns.add("SizeMB",[Decimal]) | Out-Null
$datatable.columns.add("SourceCompatibilityLevel",[String]) | Out-Null
$datatable.columns.add("TargetCompatibilityLevel",[String]) | Out-Null
$datatable.columns.add("Category",[String]) | Out-Null
@@ -826,9 +826,9 @@ INSERT INTO BreakingChangeWeighting VALUES ('Microsoft.Rules.Data.Upgrade.UR0000
{
foreach($assessment in $serverInstances.AssessmentRecommendations) #level 3, the assessment
{
$assessment.ImpactedDatabases = if ($assessment.ImpactedDatabases.Length -eq 0) {$blankImpactedDatabases} else {$assessment.ImpactedDatabases}
$impactedDatabases = if (($assessment.ImpactedDatabases -eq $null) -or ($assessment.ImpactedDatabases.Length -eq 0)) {$blankImpactedDatabases} else {$assessment.ImpactedDatabases}
foreach($impacteddbs in $assessment.ImpactedDatabases) #level 4, the impacted objects
foreach($impacteddbs in $impactedDatabases) #level 4, the impacted objects
{
#TODO Get date here will eventually be replace with timestamp from JSON file
$azuredatatable.rows.add((Get-Date).toString(), $serverInstances.ServerName, $serverInstances.Version, $serverInstances.Status, $assessment.Category, $assessment.Severity, $assessment.FeatureParityCategory, $assessment.RuleId, $assessment.Title, $assessment.Impact, $assessment.Recommendation, $assessment.MoreInfo, $impacteddbs.Name, $impacteddbs.ObjectType, $impacteddbs.ImpactDetail) | Out-Null
@@ -101,7 +101,7 @@
<DMF:Enabled type="boolean">false</DMF:Enabled>
<DMF:AutomatedPolicyEvaluationMode type="AutomatedPolicyEvaluationMode">None</DMF:AutomatedPolicyEvaluationMode>
<DMF:HelpText type="string" />
<DMF:HelpLink type="string">http://go.microsoft.com/fwlink/?LinkId=116364</DMF:HelpLink>
<DMF:HelpLink type="string">https://docs.microsoft.com/en-us/sql/relational-databases/policy-based-management/guest-permissions-on-user-databases</DMF:HelpLink>
<DMF:ActiveEndDate type="dateTime">0001-01-01T00:00:00</DMF:ActiveEndDate>
<DMF:ActiveStartDate type="dateTime">0001-01-01T00:00:00</DMF:ActiveStartDate>
</DMF:Policy>
@@ -214,4 +214,4 @@
</document>
</definitions>
</xs:bufferSchema>
</model>
</model>
@@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Belgrade.Sql.Client" Version="0.7.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.2" />
@@ -193,6 +193,7 @@ Sub Main()
Dim timeout As Integer = RsSrc.Timeout
RsSrc.Timeout = 600000 '10 minutes
srcItems = RsSrc.ListChildren(GetSrcFolderPath(), True) 'Possible catalog item types: Model, Dataset, Component, Resource, DataSource, Folder, Report
Array.Sort(srcItems, New Comparison(Of CatalogItem)(AddressOf SortParentFoldersFirst))
RsSrc.Timeout = timeout
For Each ci As CatalogItem In srcItems
@@ -656,12 +657,34 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
RsSrc.GetDataDrivenSubscriptionProperties(srcSub.SubscriptionID, extensionSettings, dataRetrievalPlan, description, active, status, eventType, matchData, parameters)
If extensionSettings.Extension = "Report Server FileShare" Then
Dim newParameterValues() As [ParameterValueOrFieldReference] = New [ParameterValueOrFieldReference](extensionSettings.ParameterValues.Length) {}
Array.Copy(extensionSettings.ParameterValues, newParameterValues, extensionSettings.ParameterValues.Length)
Dim pwdParameterValue As ParameterValue = New ParameterValue
pwdParameterValue.Label = "PASSWORD"
pwdParameterValue.Name = "PASSWORD"
pwdParameterValue.Value = "PASSWORD"
newParameterValues(extensionSettings.ParameterValues.Length) = pwdParameterValue
Dim passwordParamFound As Boolean = False
Array.Copy(extensionSettings.ParameterValues, newParameterValues, extensionSettings.ParameterValues.Length)
For Each pvofr As ParameterValueOrFieldReference In extensionSettings.ParameterValues
If TypeOf pvofr Is ParameterValue Then
Dim pv As ParameterValue = pvofr
If pv.Name.Contains("PASSWORD") Then
'Subscription has Password field linked to dataset field
passwordParamFound = True
Exit For
End If
Else If TypeOf pvofr Is ParameterFieldReference Then
Dim pfr As ParameterFieldReference = pvofr
If pfr.ParameterName.Contains("PASSWORD") Then
'Subscription has Password field linked to dataset field
passwordParamFound = True
Exit For
End If
End If
Next
If not passwordParamFound Then
'Subscription has Password field set to "Leave blank" or "Enter value"
Dim pwdParameterValue As ParameterValue = New ParameterValue
pwdParameterValue.Label = "PASSWORD"
pwdParameterValue.Name = "PASSWORD"
pwdParameterValue.Value = "PASSWORD"
newParameterValues(extensionSettings.ParameterValues.Length) = pwdParameterValue
End If
extensionSettings.ParameterValues = newParameterValues
End If
@@ -688,7 +711,8 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
RsSrc.GetSubscriptionProperties(srcSub.SubscriptionID, extensionSettings, description, active, status, eventType, matchData, parameters)
If extensionSettings.Extension = "Report Server FileShare" Then
Dim newParameterValues() As [ParameterValueOrFieldReference] = New [ParameterValueOrFieldReference](extensionSettings.ParameterValues.Length) {}
Array.Copy(extensionSettings.ParameterValues, newParameterValues, extensionSettings.ParameterValues.Length)
Array.Copy(extensionSettings.ParameterValues, newParameterValues, extensionSettings.ParameterValues.Length)
'Standard subscriptions will always require adding PASSWORD parameter during migration
Dim pwdParameterValue As ParameterValue = New ParameterValue
pwdParameterValue.Label = "PASSWORD"
pwdParameterValue.Name = "PASSWORD"
@@ -1068,3 +1092,15 @@ Sub WriteSuccess()
Console.WriteLine(" ... SUCCESS")
Console.ResetColor()
End Sub
Function SortParentFoldersFirst(first As CatalogItem, second As CatalogItem) As Integer
If first.TypeName = "Folder" And second.TypeName <> "Folder" Then
Return -1
ElseIf first.TypeName <> "Folder" And second.TypeName = "Folder" Then
Return 1
ElseIf first.TypeName <> "Folder" And second.TypeName <> "Folder" Then
Return 0
Else
Return String.Compare(first.Path, second.Path)
End If
End Function
@@ -27,27 +27,27 @@ TARGET_DOCKER_PASSWORD = getpass.getpass("Provide Docker password for the target
TARGET_DOCKER_TAG = input("Provide Docker tag for the images at the target: ") or "latest"
images = ['mssql-app-service-proxy',
'mssql-control-watchdog'
'mssql-controller'
'mssql-dns'
'mssql-hadoop'
'mssql-mleap-serving-runtime'
'mssql-mlserver-py-runtime'
'mssql-mlserver-r-runtime'
'mssql-monitor-collectd'
'mssql-monitor-elasticsearch'
'mssql-monitor-fluentbit'
'mssql-monitor-grafana'
'mssql-monitor-influxdb'
'mssql-monitor-kibana'
'mssql-monitor-telegraf'
'mssql-security-knox'
'mssql-security-support'
'mssql-server-controller'
'mssql-server-data'
'mssql-ha-operator'
'mssql-ha-supervisor'
'mssql-service-proxy'
'mssql-control-watchdog',
'mssql-controller',
'mssql-dns',
'mssql-hadoop,'
'mssql-mleap-serving-runtime',
'mssql-mlserver-py-runtime',
'mssql-mlserver-r-runtime',
'mssql-monitor-collectd',
'mssql-monitor-elasticsearch',
'mssql-monitor-fluentbit',
'mssql-monitor-grafana',
'mssql-monitor-influxdb',
'mssql-monitor-kibana',
'mssql-monitor-telegraf',
'mssql-security-knox',
'mssql-security-support',
'mssql-server-controller',
'mssql-server-data',
'mssql-ha-operator',
'mssql-ha-supervisor',
'mssql-service-proxy',
'mssql-ssis-app-runtime']
# Use this only if your source is a private Docker registry
@@ -340,7 +340,7 @@
" featureCols.append(key)\r\n",
"\r\n",
"# string-index the label column into a column named \"label\"\r\n",
"si_label = StringIndexer(inputCol=label, outputCol='label')\r\n",
"si_label = StringIndexer(inputCol=label, outputCol='label').setHandleInvalid("skip")\r\n",
"\r\n",
"# assemble the encoded feature columns in to a column named \"features\"\r\n",
"assembler = VectorAssembler(inputCols=featureCols, outputCol=\"features\")\r\n",
@@ -1,7 +1,9 @@
#Requires -Modules @{ ModuleName="AzureRM.Sql"; ModuleVersion="4.12.1" }
#Requires -Modules @{ ModuleName="Az.Sql"; ModuleVersion="3.5.1" }
#Data Sync OMS Integration Runbook
#To use this script Change all the strings below to reflect your information.
#Setup a System Managed Identity in the Automation Account, with Reader permissions to the monitored SQL targets
#Also allow the managed identity access to the Automation Account itself to read/write the Variable used
#Information for Sync Group 1
#If you want to use all the sync groups in your subscription keep the $DS_xxxx fields empty.
@@ -16,14 +18,16 @@ $DS_ServerName = ""
$DS_DatabaseName = ""
$DS_SyncGroupName = ""
# Insert your Automation Account ResourceGroup and Account names
$AC_ResourceGroupName = "ResourceGroupName"
$AC_AccountName = "AutomationAccountName"
# Insert the name of the DateTime variable in the Automation Account for storing the last synctime
$AC_LastUpdatedTimeVariableName = "DataSyncLogLastUpdatedTime"
# Replace with your OMS Workspace ID
# Replace with your OMS Workspace ID (Log Analytics Workspace ID)
$CustomerId = "OMSCustomerID"
# Replace with your OMS Primary Key
# Replace with your OMS Primary Key (Log Analytics Primary Key)
$SharedKey = "SharedKey"
# Specify the name of the record type that you'll be creating
@@ -32,35 +36,12 @@ $LogType = "DataSyncLog"
# Specify a field with the created time for the records
$TimeStampField = "DateValue"
#Specify the interval of how often you want to send data to oms
#You can use -hours, -minutes or -days, use a negative number
#$interval = New-TimeSpan -hours -1
#Connect to Azure
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process
# Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContextficateThumbprint $servicePrincipalConnection.CertificateThumbprint
# Create the function to create the authorization signature
Function Build-Signature ($customerId, $sharedKey, $date, $contentLength, $method, $contentType, $resource)
@@ -79,7 +60,6 @@ Function Build-Signature ($customerId, $sharedKey, $date, $contentLength, $metho
return $authorization
}
# Create the function to create and post the request
Function Post-OMSData($customerId, $sharedKey, $body, $logType)
{
@@ -113,19 +93,18 @@ Function Post-OMSData($customerId, $sharedKey, $body, $logType)
#Get Log Data
select-azurermsubscription -SubscriptionId $SubscriptionId
#Set the endtime, get StartTime-filter from Automation Account variable
$endtime =[System.DateTime]::UtcNow
$StartTime = Get-AzureRmAutomationVariable -ResourceGroupName $AC_ResourceGroupName `
$StartTime = Get-AzAutomationVariable -ResourceGroupName $AC_ResourceGroupName `
AutomationAccountName $AC_AccountName `
-Name $AC_LastUpdatedTimeVariableName | Select -ExpandProperty Value
#Get Log
Write-Output "Getting Data Sync Log from $StartTime to $EndTime"
if ($DS_ResourceGroupName -eq "")
{
$ResourceGroupName = Get-AzureRmResourceGroup | select -ExpandProperty ResourceGroupName
$ResourceGroupName = Get-AzResourceGroup | select -ExpandProperty ResourceGroupName
}
else
{
@@ -136,7 +115,7 @@ foreach ($ResourceGroup in $ResourceGroupName)
{
if ($DS_ServerName -eq "")
{
$ServerName = Get-AzureRmSqlServer -ResourceGroupName $ResourceGroup | select -ExpandProperty ServerName
$ServerName = Get-AzSqlServer -ResourceGroupName $ResourceGroup | select -ExpandProperty ServerName
}
else
{
@@ -147,7 +126,7 @@ foreach ($ResourceGroup in $ResourceGroupName)
{
if ($DS_DatabaseName -eq "")
{
$DatabaseName = Get-AzureRmSqlDatabase -ResourceGroupName $ResourceGroup -ServerName $Server | select -ExpandProperty DatabaseName
$DatabaseName = Get-AzSqlDatabase -ResourceGroupName $ResourceGroup -ServerName $Server | select -ExpandProperty DatabaseName
}
else
{
@@ -163,7 +142,7 @@ foreach ($ResourceGroup in $ResourceGroupName)
if ($DS_SyncGroupName -eq "")
{
$SyncGroupName = Get-AzureRmSqlSyncGroup -ResourceGroupName $ResourceGroup -ServerName $Server -DatabaseName $Database | select -ExpandProperty SyncGroupName
$SyncGroupName = Get-AzSqlSyncGroup -ResourceGroupName $ResourceGroup -ServerName $Server -DatabaseName $Database | select -ExpandProperty SyncGroupName
}
else
{
@@ -172,7 +151,7 @@ foreach ($ResourceGroup in $ResourceGroupName)
foreach ($SyncGroup in $SyncGroupName)
{
$Logs = Get-AzureRmSqlSyncGroupLog -ResourceGroupName $ResourceGroup `
$Logs = Get-AzSqlSyncGroupLog -ResourceGroupName $ResourceGroup `
-ServerName $Server `
-DatabaseName $Database `
-SyncGroupName $SyncGroup `
@@ -226,9 +205,10 @@ foreach ($ResourceGroup in $ResourceGroupName)
}
Set-AzureRmAutomationVariable -ResourceGroupName $AC_ResourceGroupName `
# Write runtime into Automation Account variable
Set-AzAutomationVariable -ResourceGroupName $AC_ResourceGroupName `
AutomationAccountName $AC_AccountName `
-DefaultProfile $AzureContext `
-Name $AC_LastUpdatedTimeVariableName `
-Value $EndTime `
-Encrypted $False
@@ -0,0 +1,44 @@
-- ==============================
-- Create Append-Only Ledger Table Template
-- Use the Specify Values for Template Parameters command (Ctrl-Shift-M) to fill in the parameter values below.
--
-- For more details on ledger tables please refer to MSDN documentation:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-overview
--
-- To learn more how to use append-only ledger tables in your applications:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-append-only-ledger-tables
-- ==============================
IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name, sysname, sample_ledger_table>', 'U') IS NOT NULL
DROP TABLE <schema_name, sysname, dbo>.<ledger_table_name, sysname, sample_ledger_table>
GO
--Create append-only ledger table.
CREATE TABLE [<schema_name, sysname, dbo>].[<ledger_table_name, sysname, sample_ledger_table>]
(
--The table must contain at least one user-defined column.
<column1_name, sysname, c1> <column1_datatype, , char(10)>,
--Ledger tables require GENERATED ALWAYS columns, which can be explicitly defined or auto-generated during table creation
<ledger_start_transaction_id_name, sysname, ledger_start_transaction_id> BIGINT GENERATED ALWAYS AS TRANSACTION_ID START,
<ledger_start_sequence_number_name, sysname, ledger_start_sequence_number> BIGINT GENERATED ALWAYS AS SEQUENCE_NUMBER START
)
WITH
(
--Set LEDGER = ON
LEDGER = ON
(
APPEND_ONLY = ON,
--Option to specify the name of the ledger view. If not supplied, the view will be created with the
--default name format: [<schema_name>].[<ledger_table_name>_Ledger]
LEDGER_VIEW = [<view_schema_name, sysname, dbo>].[<view_name, sysname, sample_ledger_view>]
(
--Options to specify ledger view default column names
TRANSACTION_ID_COLUMN_NAME = <transaction_id_column_name,, ledger_transaction_id>,
SEQUENCE_NUMBER_COLUMN_NAME = <sequence_number_column_name,, ledger_sequence_number>,
OPERATION_TYPE_COLUMN_NAME = <operation_type_id_column_name,, ledger_operation_type>,
OPERATION_TYPE_DESC_COLUMN_NAME = <operation_type_desc_column_name,, ledger_operation_type_desc>
)
)
)
@@ -0,0 +1,52 @@
-- ==============================
-- Create Updatable Ledger Table Template
-- Use the Specify Values for Template Parameters command (Ctrl-Shift-M) to fill in the parameter values below.
--
-- For more details on ledger tables please refer to MSDN documentation:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-overview
--
-- To learn more how to use updatable ledger tables in your applications:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-updatable-ledger-tables
-- ==============================
IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name, sysname, sample_ledger_table>', 'U') IS NOT NULL
DROP TABLE <schema_name, sysname, dbo>.<ledger_table_name, sysname, sample_ledger_table>
GO
--Create updatable ledger table.
CREATE TABLE [<schema_name, sysname, dbo>].[<ledger_table_name, sysname, sample_ledger_table>]
(
--The table must contain at least one user-defined column.
<column1_name, sysname, c1> <column1_datatype, , char(10)>,
--Ledger tables require GENERATED ALWAYS columns, which can be explicitly defined or auto-generated during table creation
<ledger_start_transaction_id_name, sysname, ledger_start_transaction_id> BIGINT GENERATED ALWAYS AS TRANSACTION_ID START,
<ledger_end_transaction_id_name, sysname, ledger_end_transaction_id> BIGINT GENERATED ALWAYS AS TRANSACTION_ID END,
<ledger_start_sequence_number_name, sysname, ledger_start_sequence_number> BIGINT GENERATED ALWAYS AS SEQUENCE_NUMBER START,
<ledger_end_sequence_number_name, sysname, ledger_end_sequence_number> BIGINT GENERATED ALWAYS AS SEQUENCE_NUMBER END
)
WITH
(
--Set SYSTEM_VERSIONING to ON
SYSTEM_VERSIONING = ON
(
--Option to specify the name of the ledger history table. If not supplied, the history table will be created with the
--default name format: [<schema_name>].[MSSQL_LedgerHistoryFor_<ledger_table_objectid>]
HISTORY_TABLE = [<history_table_schema_name, sysname, dbo>].[<history_table_name, sysname, sample_ledger_history>]
),
--Set LEDGER = ON. This is optional if this is a ledger database
LEDGER = ON
(
--Option to specify the name of the ledger view. If not supplied, the view will be created with the
--default name format: [<schema_name>].[<ledger_table_name>_Ledger]
LEDGER_VIEW = [<view_schema_name, sysname, dbo>].[<view_name, sysname, sample_ledger_view>]
(
--Options to specify ledger view default column names
TRANSACTION_ID_COLUMN_NAME = <transaction_id_column_name,, ledger_transaction_id>,
SEQUENCE_NUMBER_COLUMN_NAME = <sequence_number_column_name,, ledger_sequence_number>,
OPERATION_TYPE_COLUMN_NAME = <operation_type_id_column_name,, ledger_operation_type>,
OPERATION_TYPE_DESC_COLUMN_NAME = <operation_type_desc_column_name,, ledger_operation_type_desc>
)
)
)
@@ -0,0 +1,46 @@
-- ==============================
-- Create Append-Only Ledger Table Template
-- Use the Specify Values for Template Parameters command (Ctrl-Shift-M) to fill in the parameter values below.
--
-- For more details on ledger tables please refer to MSDN documentation:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-overview
--
-- To learn more how to use append-only ledger tables in your applications:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-append-only-ledger-tables
-- ==============================
USE <database_name, sysname, AdventureWorks>
GO
IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name, sysname, sample_ledger_table>', 'U') IS NOT NULL
DROP TABLE <schema_name, sysname, dbo>.<ledger_table_name, sysname, sample_ledger_table>
GO
--Create append-only ledger table.
CREATE TABLE [<schema_name, sysname, dbo>].[<ledger_table_name, sysname, sample_ledger_table>]
(
--The table must contain at least one user-defined column.
<column1_name, sysname, c1> <column1_datatype, , char(10)>,
--Ledger tables require GENERATED ALWAYS columns, which can be explicitly defined or auto-generated during table creation
<ledger_start_transaction_id_name, sysname, ledger_start_transaction_id> BIGINT GENERATED ALWAYS AS TRANSACTION_ID START,
<ledger_start_sequence_number_name, sysname, ledger_start_sequence_number> BIGINT GENERATED ALWAYS AS SEQUENCE_NUMBER START
)
WITH
(
--Set LEDGER = ON
LEDGER = ON
(
APPEND_ONLY = ON,
--Option to specify the name of the ledger view. If not supplied, the view will be created with the
--default name format: [<schema_name>].[<ledger_table_name>_Ledger]
LEDGER_VIEW = [<view_schema_name, sysname, dbo>].[<view_name, sysname, sample_ledger_view>]
(
--Options to specify ledger view default column names
TRANSACTION_ID_COLUMN_NAME = <transaction_id_column_name,, ledger_transaction_id>,
SEQUENCE_NUMBER_COLUMN_NAME = <sequence_number_column_name,, ledger_sequence_number>,
OPERATION_TYPE_COLUMN_NAME = <operation_type_id_column_name,, ledger_operation_type>,
OPERATION_TYPE_DESC_COLUMN_NAME = <operation_type_desc_column_name,, ledger_operation_type_desc>
)
)
)
@@ -0,0 +1,54 @@
-- ==============================
-- Create Updatable Ledger Table Template
-- Use the Specify Values for Template Parameters command (Ctrl-Shift-M) to fill in the parameter values below.
--
-- For more details on ledger tables please refer to MSDN documentation:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-overview
--
-- To learn more how to use updatable ledger tables in your applications:
-- https://docs.microsoft.com/azure/azure-sql/database/ledger-updatable-ledger-tables
-- ==============================
USE <database_name, sysname, AdventureWorks>
GO
IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name, sysname, sample_ledger_table>', 'U') IS NOT NULL
DROP TABLE <schema_name, sysname, dbo>.<ledger_table_name, sysname, sample_ledger_table>
GO
--Create updatable ledger table.
CREATE TABLE [<schema_name, sysname, dbo>].[<ledger_table_name, sysname, sample_ledger_table>]
(
--The table must contain at least one user-defined column.
<column1_name, sysname, c1> <column1_datatype, , char(10)>,
--Ledger tables require GENERATED ALWAYS columns, which can be explicitly defined or auto-generated during table creation
<ledger_start_transaction_id_name, sysname, ledger_start_transaction_id> BIGINT GENERATED ALWAYS AS TRANSACTION_ID START,
<ledger_end_transaction_id_name, sysname, ledger_end_transaction_id> BIGINT GENERATED ALWAYS AS TRANSACTION_ID END,
<ledger_start_sequence_number_name, sysname, ledger_start_sequence_number> BIGINT GENERATED ALWAYS AS SEQUENCE_NUMBER START,
<ledger_end_sequence_number_name, sysname, ledger_end_sequence_number> BIGINT GENERATED ALWAYS AS SEQUENCE_NUMBER END
)
WITH
(
--Set SYSTEM_VERSIONING to ON
SYSTEM_VERSIONING = ON
(
--Option to specify the name of the ledger history table. If not supplied, the history table will be created with the
--default name format: [<schema_name>].[MSSQL_LedgerHistoryFor_<ledger_table_objectid>]
HISTORY_TABLE = [<history_table_schema_name, sysname, dbo>].[<history_table_name, sysname, sample_ledger_history>]
),
--Set LEDGER = ON. This is optional if this is a ledger database
LEDGER = ON
(
--Option to specify the name of the ledger view. If not supplied, the view will be created with the
--default name format: [<schema_name>].[<ledger_table_name>_Ledger]
LEDGER_VIEW = [<view_schema_name, sysname, dbo>].[<view_name, sysname, sample_ledger_view>]
(
--Options to specify ledger view default column names
TRANSACTION_ID_COLUMN_NAME = <transaction_id_column_name,, ledger_transaction_id>,
SEQUENCE_NUMBER_COLUMN_NAME = <sequence_number_column_name,, ledger_sequence_number>,
OPERATION_TYPE_COLUMN_NAME = <operation_type_id_column_name,, ledger_operation_type>,
OPERATION_TYPE_DESC_COLUMN_NAME = <operation_type_desc_column_name,, ledger_operation_type_desc>
)
)
)