Creates or updates a database data masking rule.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/Default/rules/{dataMaskingRuleName}?api-version=2025-01-01
URI Parameters
| Name |
In |
Required |
Type |
Description |
|
databaseName
|
path |
True
|
string
|
The name of the database.
|
|
dataMaskingPolicyName
|
path |
True
|
DataMaskingPolicyName
|
The name of the database for which the data masking policy applies.
|
|
dataMaskingRuleName
|
path |
True
|
string
|
The name of the data masking rule.
|
|
resourceGroupName
|
path |
True
|
string
minLength: 1 maxLength: 90
|
The name of the resource group. The name is case insensitive.
|
|
serverName
|
path |
True
|
string
|
The name of the server.
|
|
subscriptionId
|
path |
True
|
string
(uuid)
|
The ID of the target subscription. The value must be an UUID.
|
|
api-version
|
query |
True
|
string
minLength: 1
|
The API version to use for this operation.
|
Request Body
| Name |
Required |
Type |
Description |
|
properties.columnName
|
True
|
string
|
The column name on which the data masking rule is applied.
|
|
properties.maskingFunction
|
True
|
DataMaskingFunction
|
The masking function that is used for the data masking rule.
|
|
properties.schemaName
|
True
|
string
|
The schema name on which the data masking rule is applied.
|
|
properties.tableName
|
True
|
string
|
The table name on which the data masking rule is applied.
|
|
properties.aliasName
|
|
string
|
The alias name. This is a legacy parameter and is no longer used.
|
|
properties.numberFrom
|
|
string
|
The numberFrom property of the masking rule. Required if maskingFunction is set to Number, otherwise this parameter will be ignored.
|
|
properties.numberTo
|
|
string
|
The numberTo property of the data masking rule. Required if maskingFunction is set to Number, otherwise this parameter will be ignored.
|
|
properties.prefixSize
|
|
string
|
If maskingFunction is set to Text, the number of characters to show unmasked in the beginning of the string. Otherwise, this parameter will be ignored.
|
|
properties.replacementString
|
|
string
|
If maskingFunction is set to Text, the character to use for masking the unexposed part of the string. Otherwise, this parameter will be ignored.
|
|
properties.ruleState
|
|
DataMaskingRuleState
|
The rule state. Used to delete a rule. To delete an existing rule, specify the schemaName, tableName, columnName, maskingFunction, and specify ruleState as disabled. However, if the rule doesn't already exist, the rule will be created with ruleState set to enabled, regardless of the provided value of ruleState.
|
|
properties.suffixSize
|
|
string
|
If maskingFunction is set to Text, the number of characters to show unmasked at the end of the string. Otherwise, this parameter will be ignored.
|
Responses
| Name |
Type |
Description |
|
200 OK
|
DataMaskingRule
|
Azure operation completed successfully.
|
|
201 Created
|
DataMaskingRule
|
Resource 'DataMaskingRule' create operation succeeded
|
|
Other Status Codes
|
ErrorResponse
|
An unexpected error response.
|
Security
azure_auth
Azure Active Directory OAuth2 Flow.
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
| Name |
Description |
|
user_impersonation
|
impersonate your user account
|
Examples
Create/Update data masking rule for default max.
Sample request
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-2080/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1?api-version=2025-01-01
{
"properties": {
"aliasName": "nickname",
"columnName": "test1",
"maskingFunction": "Default",
"ruleState": "Enabled",
"schemaName": "dbo",
"tableName": "Table_1"
}
}
import com.azure.resourcemanager.sql.fluent.models.DataMaskingRuleInner;
import com.azure.resourcemanager.sql.models.DataMaskingFunction;
import com.azure.resourcemanager.sql.models.DataMaskingPolicyName;
import com.azure.resourcemanager.sql.models.DataMaskingRuleState;
/**
* Samples for DataMaskingRules CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateDefaultMax.json
*/
/**
* Sample code: Create/Update data masking rule for default max.
*
* @param manager Entry point to SqlServerManager.
*/
public static void
createUpdateDataMaskingRuleForDefaultMax(com.azure.resourcemanager.sql.SqlServerManager manager) {
manager.serviceClient().getDataMaskingRules().createOrUpdateWithResponse("sqlcrudtest-6852", "sqlcrudtest-2080",
"sqlcrudtest-331", DataMaskingPolicyName.DEFAULT, "rule1",
new DataMaskingRuleInner().withRuleState(DataMaskingRuleState.ENABLED).withSchemaName("dbo")
.withTableName("Table_1").withColumnName("test1").withAliasName("nickname")
.withMaskingFunction(DataMaskingFunction.DEFAULT),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python data_masking_rule_create_or_update_default_max.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.data_masking_rules.create_or_update(
resource_group_name="sqlcrudtest-6852",
server_name="sqlcrudtest-2080",
database_name="sqlcrudtest-331",
data_masking_rule_name="rule1",
parameters={
"properties": {
"aliasName": "nickname",
"columnName": "test1",
"maskingFunction": "Default",
"ruleState": "Enabled",
"schemaName": "dbo",
"tableName": "Table_1",
}
},
)
print(response)
# x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateDefaultMax.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { SqlManagementClient } = require("@azure/arm-sql");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to creates or updates a database data masking rule.
*
* @summary creates or updates a database data masking rule.
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateDefaultMax.json
*/
async function createOrUpdateDataMaskingRuleForDefaultMax() {
const credential = new DefaultAzureCredential();
const subscriptionId = "00000000-1111-2222-3333-444444444444";
const client = new SqlManagementClient(credential, subscriptionId);
const result = await client.dataMaskingRules.createOrUpdate(
"sqlcrudtest-6852",
"sqlcrudtest-2080",
"sqlcrudtest-331",
"rule1",
{
aliasName: "nickname",
columnName: "test1",
maskingFunction: "Default",
ruleState: "Enabled",
schemaName: "dbo",
tableName: "Table_1",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/DataMaskingRuleCreateOrUpdateDefaultMax.json
// this example is just showing the usage of "DataMaskingRules_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this DataMaskingPolicyResource created on azure
// for more information of creating DataMaskingPolicyResource, please refer to the document of DataMaskingPolicyResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "sqlcrudtest-6852";
string serverName = "sqlcrudtest-2080";
string databaseName = "sqlcrudtest-331";
DataMaskingPolicyName dataMaskingPolicyName = DataMaskingPolicyName.Default;
ResourceIdentifier dataMaskingPolicyResourceId = DataMaskingPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, serverName, databaseName, dataMaskingPolicyName);
DataMaskingPolicyResource dataMaskingPolicy = client.GetDataMaskingPolicyResource(dataMaskingPolicyResourceId);
// invoke the operation
string dataMaskingRuleName = "rule1";
DataMaskingRule dataMaskingRule = new DataMaskingRule
{
RuleState = DataMaskingRuleState.Enabled,
SchemaName = "dbo",
TableName = "Table_1",
ColumnName = "test1",
AliasName = "nickname",
MaskingFunction = DataMaskingFunction.Default,
};
DataMaskingRule result = await dataMaskingPolicy.CreateOrUpdateDataMaskingRuleAsync(dataMaskingRuleName, dataMaskingRule);
Console.WriteLine($"Succeeded: {result}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": "nickname",
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Default",
"numberFrom": null,
"numberTo": null,
"prefixSize": null,
"replacementString": null,
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": null,
"tableName": "Table_1"
}
}
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": "nickname",
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Default",
"numberFrom": null,
"numberTo": null,
"prefixSize": null,
"replacementString": null,
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": null,
"tableName": "Table_1"
}
}
Create/Update data masking rule for default min.
Sample request
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-2080/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1?api-version=2025-01-01
{
"properties": {
"columnName": "test1",
"maskingFunction": "Default",
"schemaName": "dbo",
"tableName": "Table_1"
}
}
import com.azure.resourcemanager.sql.fluent.models.DataMaskingRuleInner;
import com.azure.resourcemanager.sql.models.DataMaskingFunction;
import com.azure.resourcemanager.sql.models.DataMaskingPolicyName;
/**
* Samples for DataMaskingRules CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateDefaultMin.json
*/
/**
* Sample code: Create/Update data masking rule for default min.
*
* @param manager Entry point to SqlServerManager.
*/
public static void
createUpdateDataMaskingRuleForDefaultMin(com.azure.resourcemanager.sql.SqlServerManager manager) {
manager.serviceClient().getDataMaskingRules().createOrUpdateWithResponse("sqlcrudtest-6852", "sqlcrudtest-2080",
"sqlcrudtest-331", DataMaskingPolicyName.DEFAULT, "rule1", new DataMaskingRuleInner().withSchemaName("dbo")
.withTableName("Table_1").withColumnName("test1").withMaskingFunction(DataMaskingFunction.DEFAULT),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python data_masking_rule_create_or_update_default_min.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.data_masking_rules.create_or_update(
resource_group_name="sqlcrudtest-6852",
server_name="sqlcrudtest-2080",
database_name="sqlcrudtest-331",
data_masking_rule_name="rule1",
parameters={
"properties": {
"columnName": "test1",
"maskingFunction": "Default",
"schemaName": "dbo",
"tableName": "Table_1",
}
},
)
print(response)
# x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateDefaultMin.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { SqlManagementClient } = require("@azure/arm-sql");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to creates or updates a database data masking rule.
*
* @summary creates or updates a database data masking rule.
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateDefaultMin.json
*/
async function createOrUpdateDataMaskingRuleForDefaultMin() {
const credential = new DefaultAzureCredential();
const subscriptionId = "00000000-1111-2222-3333-444444444444";
const client = new SqlManagementClient(credential, subscriptionId);
const result = await client.dataMaskingRules.createOrUpdate(
"sqlcrudtest-6852",
"sqlcrudtest-2080",
"sqlcrudtest-331",
"rule1",
{ columnName: "test1", maskingFunction: "Default", schemaName: "dbo", tableName: "Table_1" },
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/DataMaskingRuleCreateOrUpdateDefaultMin.json
// this example is just showing the usage of "DataMaskingRules_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this DataMaskingPolicyResource created on azure
// for more information of creating DataMaskingPolicyResource, please refer to the document of DataMaskingPolicyResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "sqlcrudtest-6852";
string serverName = "sqlcrudtest-2080";
string databaseName = "sqlcrudtest-331";
DataMaskingPolicyName dataMaskingPolicyName = DataMaskingPolicyName.Default;
ResourceIdentifier dataMaskingPolicyResourceId = DataMaskingPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, serverName, databaseName, dataMaskingPolicyName);
DataMaskingPolicyResource dataMaskingPolicy = client.GetDataMaskingPolicyResource(dataMaskingPolicyResourceId);
// invoke the operation
string dataMaskingRuleName = "rule1";
DataMaskingRule dataMaskingRule = new DataMaskingRule
{
SchemaName = "dbo",
TableName = "Table_1",
ColumnName = "test1",
MaskingFunction = DataMaskingFunction.Default,
};
DataMaskingRule result = await dataMaskingPolicy.CreateOrUpdateDataMaskingRuleAsync(dataMaskingRuleName, dataMaskingRule);
Console.WriteLine($"Succeeded: {result}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": null,
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Default",
"numberFrom": null,
"numberTo": null,
"prefixSize": null,
"replacementString": null,
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": null,
"tableName": "Table_1"
}
}
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": null,
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Default",
"numberFrom": null,
"numberTo": null,
"prefixSize": null,
"replacementString": null,
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": null,
"tableName": "Table_1"
}
}
Create/Update data masking rule for numbers.
Sample request
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-2080/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1?api-version=2025-01-01
{
"properties": {
"columnName": "test1",
"maskingFunction": "Number",
"numberFrom": "0",
"numberTo": "2",
"schemaName": "dbo",
"tableName": "Table_1"
}
}
import com.azure.resourcemanager.sql.fluent.models.DataMaskingRuleInner;
import com.azure.resourcemanager.sql.models.DataMaskingFunction;
import com.azure.resourcemanager.sql.models.DataMaskingPolicyName;
/**
* Samples for DataMaskingRules CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateNumber.json
*/
/**
* Sample code: Create/Update data masking rule for numbers.
*
* @param manager Entry point to SqlServerManager.
*/
public static void createUpdateDataMaskingRuleForNumbers(com.azure.resourcemanager.sql.SqlServerManager manager) {
manager.serviceClient().getDataMaskingRules().createOrUpdateWithResponse("sqlcrudtest-6852", "sqlcrudtest-2080",
"sqlcrudtest-331", DataMaskingPolicyName.DEFAULT, "rule1",
new DataMaskingRuleInner().withSchemaName("dbo").withTableName("Table_1").withColumnName("test1")
.withMaskingFunction(DataMaskingFunction.NUMBER).withNumberFrom("0").withNumberTo("2"),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python data_masking_rule_create_or_update_number.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.data_masking_rules.create_or_update(
resource_group_name="sqlcrudtest-6852",
server_name="sqlcrudtest-2080",
database_name="sqlcrudtest-331",
data_masking_rule_name="rule1",
parameters={
"properties": {
"columnName": "test1",
"maskingFunction": "Number",
"numberFrom": "0",
"numberTo": "2",
"schemaName": "dbo",
"tableName": "Table_1",
}
},
)
print(response)
# x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateNumber.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { SqlManagementClient } = require("@azure/arm-sql");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to creates or updates a database data masking rule.
*
* @summary creates or updates a database data masking rule.
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateNumber.json
*/
async function createOrUpdateDataMaskingRuleForNumbers() {
const credential = new DefaultAzureCredential();
const subscriptionId = "00000000-1111-2222-3333-444444444444";
const client = new SqlManagementClient(credential, subscriptionId);
const result = await client.dataMaskingRules.createOrUpdate(
"sqlcrudtest-6852",
"sqlcrudtest-2080",
"sqlcrudtest-331",
"rule1",
{
columnName: "test1",
maskingFunction: "Number",
numberFrom: "0",
numberTo: "2",
schemaName: "dbo",
tableName: "Table_1",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/DataMaskingRuleCreateOrUpdateNumber.json
// this example is just showing the usage of "DataMaskingRules_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this DataMaskingPolicyResource created on azure
// for more information of creating DataMaskingPolicyResource, please refer to the document of DataMaskingPolicyResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "sqlcrudtest-6852";
string serverName = "sqlcrudtest-2080";
string databaseName = "sqlcrudtest-331";
DataMaskingPolicyName dataMaskingPolicyName = DataMaskingPolicyName.Default;
ResourceIdentifier dataMaskingPolicyResourceId = DataMaskingPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, serverName, databaseName, dataMaskingPolicyName);
DataMaskingPolicyResource dataMaskingPolicy = client.GetDataMaskingPolicyResource(dataMaskingPolicyResourceId);
// invoke the operation
string dataMaskingRuleName = "rule1";
DataMaskingRule dataMaskingRule = new DataMaskingRule
{
SchemaName = "dbo",
TableName = "Table_1",
ColumnName = "test1",
MaskingFunction = DataMaskingFunction.Number,
NumberFrom = "0",
NumberTo = "2",
};
DataMaskingRule result = await dataMaskingPolicy.CreateOrUpdateDataMaskingRuleAsync(dataMaskingRuleName, dataMaskingRule);
Console.WriteLine($"Succeeded: {result}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": null,
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Number",
"numberFrom": "0",
"numberTo": "2",
"prefixSize": null,
"replacementString": null,
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": null,
"tableName": "Table_1"
}
}
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": null,
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Number",
"numberFrom": "0",
"numberTo": "2",
"prefixSize": null,
"replacementString": null,
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": null,
"tableName": "Table_1"
}
}
Create/Update data masking rule for text.
Sample request
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-2080/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1?api-version=2025-01-01
{
"properties": {
"columnName": "test1",
"maskingFunction": "Text",
"prefixSize": "1",
"replacementString": "asdf",
"schemaName": "dbo",
"suffixSize": "0",
"tableName": "Table_1"
}
}
import com.azure.resourcemanager.sql.fluent.models.DataMaskingRuleInner;
import com.azure.resourcemanager.sql.models.DataMaskingFunction;
import com.azure.resourcemanager.sql.models.DataMaskingPolicyName;
/**
* Samples for DataMaskingRules CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateText.json
*/
/**
* Sample code: Create/Update data masking rule for text.
*
* @param manager Entry point to SqlServerManager.
*/
public static void createUpdateDataMaskingRuleForText(com.azure.resourcemanager.sql.SqlServerManager manager) {
manager.serviceClient().getDataMaskingRules().createOrUpdateWithResponse("sqlcrudtest-6852", "sqlcrudtest-2080",
"sqlcrudtest-331", DataMaskingPolicyName.DEFAULT, "rule1",
new DataMaskingRuleInner().withSchemaName("dbo").withTableName("Table_1").withColumnName("test1")
.withMaskingFunction(DataMaskingFunction.TEXT).withPrefixSize("1").withSuffixSize("0")
.withReplacementString("asdf"),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.sql import SqlManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-sql
# USAGE
python data_masking_rule_create_or_update_text.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SqlManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.data_masking_rules.create_or_update(
resource_group_name="sqlcrudtest-6852",
server_name="sqlcrudtest-2080",
database_name="sqlcrudtest-331",
data_masking_rule_name="rule1",
parameters={
"properties": {
"columnName": "test1",
"maskingFunction": "Text",
"prefixSize": "1",
"replacementString": "asdf",
"schemaName": "dbo",
"suffixSize": "0",
"tableName": "Table_1",
}
},
)
print(response)
# x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateText.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { SqlManagementClient } = require("@azure/arm-sql");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to creates or updates a database data masking rule.
*
* @summary creates or updates a database data masking rule.
* x-ms-original-file: 2025-01-01/DataMaskingRuleCreateOrUpdateText.json
*/
async function createOrUpdateDataMaskingRuleForText() {
const credential = new DefaultAzureCredential();
const subscriptionId = "00000000-1111-2222-3333-444444444444";
const client = new SqlManagementClient(credential, subscriptionId);
const result = await client.dataMaskingRules.createOrUpdate(
"sqlcrudtest-6852",
"sqlcrudtest-2080",
"sqlcrudtest-331",
"rule1",
{
columnName: "test1",
maskingFunction: "Text",
prefixSize: "1",
replacementString: "asdf",
schemaName: "dbo",
suffixSize: "0",
tableName: "Table_1",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/SQL/stable/2025-01-01/examples/DataMaskingRuleCreateOrUpdateText.json
// this example is just showing the usage of "DataMaskingRules_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this DataMaskingPolicyResource created on azure
// for more information of creating DataMaskingPolicyResource, please refer to the document of DataMaskingPolicyResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "sqlcrudtest-6852";
string serverName = "sqlcrudtest-2080";
string databaseName = "sqlcrudtest-331";
DataMaskingPolicyName dataMaskingPolicyName = DataMaskingPolicyName.Default;
ResourceIdentifier dataMaskingPolicyResourceId = DataMaskingPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, serverName, databaseName, dataMaskingPolicyName);
DataMaskingPolicyResource dataMaskingPolicy = client.GetDataMaskingPolicyResource(dataMaskingPolicyResourceId);
// invoke the operation
string dataMaskingRuleName = "rule1";
DataMaskingRule dataMaskingRule = new DataMaskingRule
{
SchemaName = "dbo",
TableName = "Table_1",
ColumnName = "test1",
MaskingFunction = DataMaskingFunction.Text,
PrefixSize = "1",
SuffixSize = "0",
ReplacementString = "asdf",
};
DataMaskingRule result = await dataMaskingPolicy.CreateOrUpdateDataMaskingRuleAsync(dataMaskingRuleName, dataMaskingRule);
Console.WriteLine($"Succeeded: {result}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": null,
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Text",
"numberFrom": null,
"numberTo": null,
"prefixSize": "1",
"replacementString": "asdf",
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": "0",
"tableName": "Table_1"
}
}
{
"name": null,
"type": "Microsoft.Sql/servers/databases/dataMaskingPolicies/rules",
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-6852/providers/Microsoft.Sql/servers/sqlcrudtest-6852/databases/sqlcrudtest-331/dataMaskingPolicies/Default/rules/rule1",
"kind": null,
"location": "Central US",
"properties": {
"aliasName": null,
"columnName": "test1",
"id": "dbo_Table_1_test1",
"maskingFunction": "Text",
"numberFrom": null,
"numberTo": null,
"prefixSize": "1",
"replacementString": "asdf",
"ruleState": "Enabled",
"schemaName": "dbo",
"suffixSize": "0",
"tableName": "Table_1"
}
}
Definitions
| Name |
Description |
|
createdByType
|
The type of identity that created the resource.
|
|
DataMaskingFunction
|
The masking function that is used for the data masking rule.
|
|
DataMaskingPolicyName
|
The name of the database for which the data masking policy applies.
|
|
DataMaskingRule
|
A database data masking rule.
|
|
DataMaskingRuleState
|
The rule state. Used to delete a rule. To delete an existing rule, specify the schemaName, tableName, columnName, maskingFunction, and specify ruleState as disabled. However, if the rule doesn't already exist, the rule will be created with ruleState set to enabled, regardless of the provided value of ruleState.
|
|
ErrorAdditionalInfo
|
The resource management error additional info.
|
|
ErrorDetail
|
The error detail.
|
|
ErrorResponse
|
Error response
|
|
systemData
|
Metadata pertaining to creation and last modification of the resource.
|
createdByType
Enumeration
The type of identity that created the resource.
| Value |
Description |
|
User
|
|
|
Application
|
|
|
ManagedIdentity
|
|
|
Key
|
|
DataMaskingFunction
Enumeration
The masking function that is used for the data masking rule.
| Value |
Description |
|
Default
|
Default
|
|
CCN
|
CCN
|
|
Email
|
Email
|
|
Number
|
Number
|
|
SSN
|
SSN
|
|
Text
|
Text
|
DataMaskingPolicyName
Enumeration
The name of the database for which the data masking policy applies.
| Value |
Description |
|
Default
|
Default
|
DataMaskingRule
Object
A database data masking rule.
| Name |
Type |
Description |
|
id
|
string
(arm-id)
|
Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}"
|
|
kind
|
string
|
The kind of Data Masking Rule. Metadata, used for Azure portal.
|
|
location
|
string
|
The location of the data masking rule.
|
|
name
|
string
|
The name of the resource
|
|
properties.aliasName
|
string
|
The alias name. This is a legacy parameter and is no longer used.
|
|
properties.columnName
|
string
|
The column name on which the data masking rule is applied.
|
|
properties.id
|
string
|
The rule Id.
|
|
properties.maskingFunction
|
DataMaskingFunction
|
The masking function that is used for the data masking rule.
|
|
properties.numberFrom
|
string
|
The numberFrom property of the masking rule. Required if maskingFunction is set to Number, otherwise this parameter will be ignored.
|
|
properties.numberTo
|
string
|
The numberTo property of the data masking rule. Required if maskingFunction is set to Number, otherwise this parameter will be ignored.
|
|
properties.prefixSize
|
string
|
If maskingFunction is set to Text, the number of characters to show unmasked in the beginning of the string. Otherwise, this parameter will be ignored.
|
|
properties.replacementString
|
string
|
If maskingFunction is set to Text, the character to use for masking the unexposed part of the string. Otherwise, this parameter will be ignored.
|
|
properties.ruleState
|
DataMaskingRuleState
|
The rule state. Used to delete a rule. To delete an existing rule, specify the schemaName, tableName, columnName, maskingFunction, and specify ruleState as disabled. However, if the rule doesn't already exist, the rule will be created with ruleState set to enabled, regardless of the provided value of ruleState.
|
|
properties.schemaName
|
string
|
The schema name on which the data masking rule is applied.
|
|
properties.suffixSize
|
string
|
If maskingFunction is set to Text, the number of characters to show unmasked at the end of the string. Otherwise, this parameter will be ignored.
|
|
properties.tableName
|
string
|
The table name on which the data masking rule is applied.
|
|
systemData
|
systemData
|
Azure Resource Manager metadata containing createdBy and modifiedBy information.
|
|
type
|
string
|
The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts"
|
DataMaskingRuleState
Enumeration
The rule state. Used to delete a rule. To delete an existing rule, specify the schemaName, tableName, columnName, maskingFunction, and specify ruleState as disabled. However, if the rule doesn't already exist, the rule will be created with ruleState set to enabled, regardless of the provided value of ruleState.
| Value |
Description |
|
Enabled
|
Enabled
|
|
Disabled
|
Disabled
|
ErrorAdditionalInfo
Object
The resource management error additional info.
| Name |
Type |
Description |
|
info
|
object
|
The additional info.
|
|
type
|
string
|
The additional info type.
|
ErrorDetail
Object
The error detail.
| Name |
Type |
Description |
|
additionalInfo
|
ErrorAdditionalInfo[]
|
The error additional info.
|
|
code
|
string
|
The error code.
|
|
details
|
ErrorDetail[]
|
The error details.
|
|
message
|
string
|
The error message.
|
|
target
|
string
|
The error target.
|
ErrorResponse
Object
Error response
| Name |
Type |
Description |
|
error
|
ErrorDetail
|
The error object.
|
systemData
Object
Metadata pertaining to creation and last modification of the resource.
| Name |
Type |
Description |
|
createdAt
|
string
(date-time)
|
The timestamp of resource creation (UTC).
|
|
createdBy
|
string
|
The identity that created the resource.
|
|
createdByType
|
createdByType
|
The type of identity that created the resource.
|
|
lastModifiedAt
|
string
(date-time)
|
The timestamp of resource last modification (UTC)
|
|
lastModifiedBy
|
string
|
The identity that last modified the resource.
|
|
lastModifiedByType
|
createdByType
|
The type of identity that last modified the resource.
|