Udostępnij za pośrednictwem


Samouczek: klonowanie tabeli przy użyciu języka T-SQL w usłudze Warehouse

Applies to:✅ Warehouse in Microsoft Fabric

Z tego samouczka dowiesz się, jak sklonować tabelę przy użyciu języka T-SQL. Specifically, you learn how to create a table clone with the CREATE TABLE AS CLONE OF T-SQL statement.

Notatka

This tutorial forms part of an end-to-end scenario. Aby ukończyć ten samouczek, należy najpierw wykonać następujące samouczki:

  1. Tworzenie obszaru roboczego
  2. Tworzenie magazynu
  3. Ingest data into a Warehouse
  4. Tworzenie tabel za pomocą języka T-SQL w magazynie danych

Sklonowana tabela zapewnia kilka korzyści:

Klonowanie tabeli w tym samym schemacie

W tym zadaniu dowiesz się, jak sklonować tabelę w tym samym schemacie w magazynie.

  1. Ensure that the workspace you created in the first tutorial is open.

  2. In the Wide World Importers warehouse, on the Home ribbon, select New SQL query.

    Zrzut ekranu przedstawiający opcję Nowe zapytanie SQL na wstążce.

  3. W edytorze zapytań wklej następujący kod. Kod tworzy klon tabeli dimension_city i tabelę fact_sale.

     --Create a clone of the dbo.dimension_city table.
     CREATE TABLE [dbo].[dimension_city1] AS CLONE OF [dbo].[dimension_city];
    
     --Create a clone of the dbo.fact_sale table.
     CREATE TABLE [dbo].[fact_sale1] AS CLONE OF [dbo].[fact_sale];
    
  4. Aby wykonać zapytanie, na wstążce projektanta zapytań wybierz pozycję Uruchom.

    Zrzut ekranu przedstawiający opcję Uruchom na wstążce edytora zapytań.

  5. Po zakończeniu wykonywania, aby wyświetlić podgląd załadowanych danych, w okienku Eksploratora wybierz pozycję .

    Screenshot of the Explorer pane, highlighting the dimension city 1 table.

  6. To create a table clone as of a past point in time, in the query editor, paste the following code to replace the existing statements. Kod tworzy klon tabeli dimension_city i tabelę fact_sale w określonym momencie w czasie.

     --Create a clone of the dbo.dimension_city table at a specific point in time.   
    CREATE TABLE [dbo].[dimension_city2] AS CLONE OF [dbo].[dimension_city] AT '2025-01-01T10:00:00.000';
    
     --Create a clone of the dbo.fact_sale table at a specific point in time.
    CREATE TABLE [dbo].[fact_sale2] AS CLONE OF [dbo].[fact_sale] AT '2025-01-01T10:00:00.000';
    

    Ważny

    You should replace the timestamp with a past date that is within 30 days of today, but after the date and time (in Coordinated Universal Time—UTC) that you completed the Ingest data into a Warehouse tutorial.

  7. Uruchom zapytanie.

  8. Po zakończeniu wykonywania wyświetl podgląd danych załadowanych do tabeli fact_sale2.

  9. Zmień nazwę zapytania na Clone Tables.

Clone a table across schemas within the same warehouse

In this task, learn how to clone a table across schemas within the same warehouse.

  1. Aby utworzyć nowe zapytanie, na wstążce Strona główna wybierz pozycję Nowe zapytanie SQL.

  2. W edytorze zapytań wklej następujący kod. Kod tworzy schemat, a następnie utwórz klon tabeli fact_sale i tabelę dimension_city w nowym schemacie.

     --Create a new schema within the warehouse named dbo1.
     CREATE SCHEMA dbo1;
     GO
    
     --Create a clone of dbo.fact_sale table in the dbo1 schema.
     CREATE TABLE [dbo1].[fact_sale1] AS CLONE OF [dbo].[fact_sale];
    
     --Create a clone of dbo.dimension_city table in the dbo1 schema.
     CREATE TABLE [dbo1].[dimension_city1] AS CLONE OF [dbo].[dimension_city];
    
  3. Uruchom zapytanie.

  4. Po zakończeniu wykonywania wyświetl podgląd danych załadowanych do tabeli dimension_city1 w schemacie dbo1.

  5. To create table clones as of a previous point in time, in the query editor, paste the following code to replace the existing statements. Kod tworzy klon tabeli dimension_city i tabelę fact_sale w określonych punktach w czasie w nowym schemacie.

    --Create a clone of the dbo.dimension_city table in the dbo1 schema.
    CREATE TABLE [dbo1].[dimension_city2] AS CLONE OF [dbo].[dimension_city] AT '2025-01-01T10:00:00.000';
    
    --Create a clone of the dbo.fact_sale table in the dbo1 schema.
    CREATE TABLE [dbo1].[fact_sale2] AS CLONE OF [dbo].[fact_sale] AT '2025-01-01T10:00:00.000';
    

    Ważny

    You should replace the timestamp with a past date that is within 30 days of today, but after the date and time (in UTC) that you completed the Ingest data into a Warehouse tutorial.

  6. Uruchom zapytanie.

  7. Po zakończeniu wykonywania wyświetl podgląd danych załadowanych do tabeli fact_sale2 w schemacie dbo1.

  8. Zmień nazwę zapytania na Clone Tables Across Schemas.

Next step