Clone a database schema in Azure Data Explorer

This article explains how to use management commands to clone an Azure Data Explorer database schema.

Prerequisites

Clone a database schema

The following steps describe how to clone a database schema using the Azure Data Explorer web UI. Alternatively, you can use the Kusto client libraries to run the same management commands. For more information, see Create an app to run management commands.

  1. From the left menu, select Query.

  2. In the connection pane, select the database whose schema you want to clone.

    Screenshot of selected database in connection pane.

  3. Run the following command:

    .show database schema as csl script with (ShowObfuscatedStrings = true)
    

    This command returns a script of management commands to recreate the database schema. Note the number of returned records, which is used for verification in a later step. For more information, see .show database schema command.

  4. Copy the CSL script output. To do so, select all of the returned rows. Then, either right-click and select Copy or use the Ctrl + C keyboard shortcut.

    Screenshot of the selected records and right-click menu.

  5. In the connection pane, select the database where you want to recreate the schema. If necessary, create a database.

    Screenshot of the other selected database in connection pane.

  6. Modify the copied script by replacing the original database name with the new database name.

  7. Run the following command, replacing <CSLScript> with the script.

    Note

    Select the full command text and then run it. If you don't select the full text, the command will stop at the first empty line in the script.

    .execute database script <| <CSLScript>
    

    This command runs the commands from the script, recreating the database schema on the new database. For more information, see .execute database script command.

  8. Verify that the script ran correctly. To do so, check that the number of returned records is the same as the records from the show schema command. Then, scroll to the final command and check that the Result column is Complete. If a failure occurs, troubleshoot and run the command again.

    Note

    You can rerun the script as often as needed without clearing resources from the previous run.