Perintah CreateOrReplace (TMSL)
Berlaku untuk: SQL Server 2016 dan yang lebih baru Analysis Services Azure Analysis Services Fabric/Power BI Premium
Membuat atau mengganti objek yang ditentukan dan semua objek turunan yang ditentukan. Objek yang tidak ada dibuat. Objek yang ada diganti dengan definisi baru.
Setiap kali Anda menentukan properti baca-tulis, pastikan untuk menyertakan semuanya. Kelalaian objek baca-tulis dianggap sebagai penghapusan.
Minta
Struktur permintaan bervariasi berdasarkan objek . Objek yang merupakan induk harus mencakup semua turunannya, meskipun definisi objek lengkap dari saudara dan induk tidak diperlukan.
Mengganti database yang sudah ada dengan definisi database minimal yang diganti namanya yang menentukan namanya, properti model yang dimodifikasi, dan koneksi. Karena definisi objek tidak menyertakan tabel, partisi, atau hubungan, semua objek tersebut dihapus.
{
"createOrReplace": {
"object": {
"database": "AdventureWorksTabular1200"
},
"database": {
"name": "TestCreateOrReplaceDB",
"id": "newID",
"compatibilityLevel": 1200,
"model": {
"defaultMode": "import",
"culture": "en-US",
"dataSources": [
{
"name": "SqlServer localhost AdventureworksDW2016",
"connectionString": "Provider=SQLNCLI11;Data Source=localhost;Initial Catalog=AdventureworksDW2016;Integrated Security=SSPI;Persist Security Info=false",
"impersonationMode": "impersonateAccount",
"account": " ",
"annotations": [
{
"name": "ConnectionEditUISource",
"value": "SqlServer"
}
]
}
]
}
}
}
}
Objek DataSources (TMSL) Menggantikan nama koneksi.
{
"createOrReplace": {
"object": {
"database": "TestCreateOrReplaceDB",
"dataSource": "SqlServer localhost AdventureworksDW2016"
},
"dataSource": {
"name": "New connection name",
"connectionString": "Provider=SQLNCLI11;Data Source=localhost;Initial Catalog=AdventureworksDW2016;Integrated Security=SSPI;Persist Security Info=false",
"impersonationMode": "impersonateAccount",
"account": " ",
"annotations": [
{
"name": "ConnectionEditUISource",
"value": "SqlServer"
}
]
}
}
}
Objek tabel (TMSL) Menimpa tabel yang ada, hanya menyisakan tabel yang ditentukan.
{
"createOrReplace": {
"object": {
"database": "AdventureWorksTabular1200"
},
"database": {
"name": "AdventureWorksTabular1200",
"id": "New-AdventureWorksTabular1200",
"compatibilityLevel": 1200,
"model": {
"defaultMode": "import",
"culture": "en-US",
"dataSources": [
{
"name": "SqlServer localhost AdventureworksDW2016",
"connectionString": "Provider=SQLNCLI11;Data Source=localhost;Initial Catalog=AdventureworksDW2016;Integrated Security=SSPI;Persist Security Info=false",
"impersonationMode": "impersonateAccount",
"account": " ",
"annotations": [
{
"name": "ConnectionEditUISource",
"value": "SqlServer"
}
]
}
],
"tables": [
{
"name": "Date",
"columns": [
{
"name": "DateKey",
"dataType": "int64",
"sourceColumn": "DateKey",
"sourceProviderType": "Integer"
},
{
"name": "FullDateAlternateKey",
"dataType": "dateTime",
"sourceColumn": "FullDateAlternateKey",
"formatString": "General Date",
"sourceProviderType": "DBDate"
},
{
"name": "CalendarYear",
"dataType": "int64",
"sourceColumn": "CalendarYear",
"sourceProviderType": "SmallInt"
}
],
"partitions": [
{
"name": "DimDate",
"dataView": "full",
"source": {
"query": " SELECT [dbo].[DimDate].* FROM [dbo].[DimDate] ",
"dataSource": "SqlServer localhost AdventureworksDW2016"
}
}
],
"annotations": [
{
"name": "_TM_ExtProp_QueryDefinition",
"value": " SELECT [dbo].[DimDate].* FROM [dbo].[DimDate] "
},
{
"name": "_TM_ExtProp_DbTableName",
"value": "DimDate"
},
{
"name": "_TM_ExtProp_DbSchemaName",
"value": "dbo"
}
]
}
]
}
}
}
}
Ganti nama partisi. Objek partisi memiliki tiga properti baca-tulis: nama, sumber, deskripsi. Setiap kali Anda menentukan properti baca-tulis, pastikan untuk menyertakan semuanya. Kelalaian objek baca-tulis dianggap sebagai penghapusan.
Karena definisi objek adalah partisi, hanya partisi bernama dan definisinya yang terpengaruh. Tabel, hubungan, dan partisi lainnya tidak terpengaruh.
Kecuali Anda membuat, mengganti, atau mengubah objek sumber data itu sendiri, sumber data apa pun yang direferensikan dalam skrip Anda (seperti dalam skrip partisi di bawah) harus menjadi objek DataSource yang ada dalam model Anda. Jika Anda perlu mengubah sumber data, tambahkan ke
{
"createOrReplace": {
"object": {
"database": "AdventureWorksTabular1200",
"table": "FactSalesQuota",
"partition": "FactSalesQuota - 2011"
},
"partition": {
"name": "Sales Quota for 2011",
"mode": "import",
"dataView": "full",
"source": {
"query": [
"SELECT [dbo].[FactSalesQuota].* FROM [dbo].[FactSalesQuota]",
"JOIN DimDate as DD",
"on DD.DateKey = FactSalesQuota.DateKey",
"WHERE DD.CalendarYear='2011'"
],
"dataSource": "SqlServer localhost AdventureworksDW2016"
}
}
}
}
Objek peran (TMSL) Mengganti definisi peran dengan definisi yang menyertakan anggota.
{
"createOrReplace": {
"object": {
"database": "AdventureWorksTabular1200",
"role": "DataReader"
},
"role": {
"name": "DataReader",
"modelPermission": "read",
"members": [
{
"memberName": "ADVENTUREWORKS\\InternalSalesGrp"
}
]
}
}
}
Respons
Mengembalikan hasil kosong saat perintah berhasil. Jika tidak, pengecualian XMLA dikembalikan.
Contoh
Contoh 1 - Membuat database baru, menimpa database yang sudah ada dengan nama yang sama.
{
"createOrReplace": {
"object": {
"database": "AdventureWorksTabular1200"
},
"database": {
"name": "AdventureWorksTabular1200",
"id": "AdventureWorksTabular1200",
"compatibilityLevel": 1200,
"model": {
"defaultMode": "directQuery",
"culture": "en-US",
"dataSources": [
{
"name": "SqlServer localhost AdventureworksDW2016",
"connectionString": "Provider=SQLNCLI11;Data Source=localhost;Initial Catalog=AdventureworksDW2016;Integrated Security=SSPI;Persist Security Info=false",
"impersonationMode": "impersonateAccount",
"account": " ",
"annotations": [
{
"name": "ConnectionEditUISource",
"value": "SqlServer"
}
]
}
],
"tables": [
{
"name": "DimDate",
"columns": [
{
"name": "DateKey",
"dataType": "int64",
"sourceColumn": "DateKey",
"sourceProviderType": "Integer"
},
{
"name": "FullDateAlternateKey",
"dataType": "dateTime",
"sourceColumn": "FullDateAlternateKey",
"formatString": "General Date",
"sourceProviderType": "DBDate"
},
{
"name": "CalendarYear",
"dataType": "int64",
"sourceColumn": "CalendarYear",
"sourceProviderType": "SmallInt"
}
],
"partitions": [
{
"name": "DimDate",
"dataView": "full",
"source": {
"query": " SELECT [dbo].[DimDate].* FROM [dbo].[DimDate] ",
"dataSource": "SqlServer localhost AdventureworksDW2016"
}
}
],
"annotations": [
{
"name": "_TM_ExtProp_QueryDefinition",
"value": " SELECT [dbo].[DimDate].* FROM [dbo].[DimDate] "
},
{
"name": "_TM_ExtProp_DbTableName",
"value": "DimDate"
},
{
"name": "_TM_ExtProp_DbSchemaName",
"value": "dbo"
}
]
},
{
"name": "DimEmployee",
"columns": [
{
"name": "EmployeeKey",
"dataType": "int64",
"sourceColumn": "EmployeeKey",
"sourceProviderType": "Integer"
},
{
"name": "SalesTerritoryKey",
"dataType": "int64",
"sourceColumn": "SalesTerritoryKey",
"sourceProviderType": "Integer"
},
{
"name": "FirstName",
"dataType": "string",
"sourceColumn": "FirstName",
"sourceProviderType": "WChar"
},
{
"name": "LastName",
"dataType": "string",
"sourceColumn": "LastName",
"sourceProviderType": "WChar"
},
{
"name": "MiddleName",
"dataType": "string",
"sourceColumn": "MiddleName",
"sourceProviderType": "WChar"
},
{
"name": "SalesPersonFlag",
"dataType": "boolean",
"sourceColumn": "SalesPersonFlag",
"formatString": "\"TRUE\";\"TRUE\";\"FALSE\"",
"sourceProviderType": "Boolean"
},
{
"name": "DepartmentName",
"dataType": "string",
"sourceColumn": "DepartmentName",
"sourceProviderType": "WChar"
}
],
"partitions": [
{
"name": "DimEmployee",
"dataView": "full",
"source": {
"query": " SELECT [dbo].[DimEmployee].* FROM [dbo].[DimEmployee] ",
"dataSource": "SqlServer localhost AdventureworksDW2016"
}
}
],
"annotations": [
{
"name": "_TM_ExtProp_QueryDefinition",
"value": " SELECT [dbo].[DimEmployee].* FROM [dbo].[DimEmployee] "
},
{
"name": "_TM_ExtProp_DbTableName",
"value": "DimEmployee"
},
{
"name": "_TM_ExtProp_DbSchemaName",
"value": "dbo"
}
]
},
{
"name": "FactSalesQuota",
"columns": [
{
"name": "SalesQuotaKey",
"dataType": "int64",
"sourceColumn": "SalesQuotaKey",
"sourceProviderType": "Integer"
},
{
"name": "EmployeeKey",
"dataType": "int64",
"sourceColumn": "EmployeeKey",
"sourceProviderType": "Integer"
},
{
"name": "DateKey",
"dataType": "int64",
"sourceColumn": "DateKey",
"sourceProviderType": "Integer"
},
{
"name": "CalendarYear",
"dataType": "int64",
"sourceColumn": "CalendarYear",
"sourceProviderType": "SmallInt"
},
{
"name": "SalesAmountQuota",
"dataType": "decimal",
"sourceColumn": "SalesAmountQuota",
"formatString": "\\$#,0.00;(\\$#,0.00);\\$#,0.00",
"sourceProviderType": "Currency",
"annotations": [
{
"name": "Format",
"value": "\<Format Format=\"Currency\" Accuracy=\"2\" ThousandSeparator=\"True\">\<Currency LCID=\"1033\" DisplayName=\"$ English (United States)\" Symbol=\"$\" PositivePattern=\"0\" NegativePattern=\"0\" /></Format>"
}
]
},
{
"name": "Date",
"dataType": "dateTime",
"sourceColumn": "Date",
"formatString": "General Date",
"sourceProviderType": "DBTimeStamp"
}
],
"partitions": [
{
"name": "FactSalesQuota",
"dataView": "full",
"source": {
"query": " SELECT [dbo].[FactSalesQuota].* FROM [dbo].[FactSalesQuota] ",
"dataSource": "SqlServer localhost AdventureworksDW2016"
}
},
{
"name": "FactSalesQuota - 2011",
"mode": "import",
"dataView": "sample",
"source": {
"query": [
"SELECT [dbo].[FactSalesQuota].* FROM [dbo].[FactSalesQuota]",
"JOIN DimDate as DD",
"on DD.DateKey = FactSalesQuota.DateKey",
"WHERE DD.CalendarYear='2011'"
],
"dataSource": "SqlServer localhost AdventureworksDW2016"
},
"annotations": [
{
"name": "QueryEditorSerialization",
"value": [
"\<?xml version=\"1.0\" encoding=\"UTF-16\"?>\<Gemini xmlns=\"QueryEditorSerialization\"><AnnotationContent><![CDATA[<RSQueryCommandText>SELECT [dbo].[FactSalesQuota].* FROM [dbo].[FactSalesQuota]",
"JOIN DimDate as DD",
"on DD.DateKey = FactSalesQuota.DateKey",
"WHERE DD.CalendarYear='2011'</RSQueryCommandText><RSQueryCommandType>Text</RSQueryCommandType><RSQueryDesignState></RSQueryDesignState>]]></AnnotationContent></Gemini>"
]
}
]
}
],
"annotations": [
{
"name": "_TM_ExtProp_QueryDefinition",
"value": " SELECT [dbo].[FactSalesQuota].* FROM [dbo].[FactSalesQuota] "
},
{
"name": "_TM_ExtProp_DbTableName",
"value": "FactSalesQuota"
},
{
"name": "_TM_ExtProp_DbSchemaName",
"value": "dbo"
}
]
}
],
"relationships": [
{
"name": "4426b078-193f-4a59-bc52-33f990bfb7da",
"fromTable": "FactSalesQuota",
"fromColumn": "DateKey",
"toTable": "DimDate",
"toColumn": "DateKey"
},
{
"name": "cde1e139-4553-4d0a-a025-1cd98e35aab2",
"fromTable": "FactSalesQuota",
"fromColumn": "EmployeeKey",
"toTable": "DimEmployee",
"toColumn": "EmployeeKey"
}
]
}
}
}
}
Penggunaan (titik akhir)
Elemen perintah ini digunakan dalam pernyataan panggilan Metode Eksekusi (XMLA) melalui titik akhir XMLA, diekspos dengan cara berikut:
Sebagai jendela XMLA di SQL Server Management Studio (SSMS)
Sebagai file input ke cmdlet PowerShell invoke-ascmd
Sebagai input ke tugas SSIS atau pekerjaan SQL Server Agent
Anda dapat membuat skrip siap pakai untuk perintah ini dari SQL Server Management Directory. Misalnya, Anda bisa mengklik kanan Database Skrip Skrip> database > yang sudah adasebagai>CREATE atau REPLACE To.