Поделиться через


Руководство. Создание таблиц с помощью T-SQL в хранилище

Applies to:✅ Warehouse in Microsoft Fabric

В этом руководстве описано, как создавать таблицы в хранилище с помощью T-SQL.

Заметка

This tutorial forms part of an end-to-end scenario. Чтобы завершить это руководство, необходимо сначала выполнить эти уроки.

  1. создание рабочей области
  2. создать склад
  3. Ingest data into a warehouse

Создание таблиц

В этой задаче вы узнаете, как создавать таблицы в хранилище с помощью T-SQL.

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

  2. Select the Wide World Importers warehouse (from the items listed on the workspace landing page).

  3. На ленте Главная выберите Новый SQL-запрос.

    снимок экрана ленты

  4. In the query editor, paste the following code. Код удаляет таблицу dimension_city (если она существует), а затем создает таблицу измерений. Она также удаляет таблицу fact_sale (если она существует) и создает таблицу фактов.

     --Drop the dimension_city table if it already exists.
     DROP TABLE IF EXISTS [dbo].[dimension_city];
    
     --Create the dimension_city table.
     CREATE TABLE [dbo].[dimension_city]
     (
        [CityKey] [int] NULL,
        [WWICityID] [int] NULL,
        [City] [varchar](8000) NULL,
        [StateProvince] [varchar](8000) NULL,
        [Country] [varchar](8000) NULL,
        [Continent] [varchar](8000) NULL,
        [SalesTerritory] [varchar](8000) NULL,
        [Region] [varchar](8000) NULL,
        [Subregion] [varchar](8000) NULL,
        [Location] [varchar](8000) NULL,
        [LatestRecordedPopulation] [bigint] NULL,
        [ValidFrom] [datetime2](6) NULL,
        [ValidTo] [datetime2](6) NULL,
        [LineageKey] [int] NULL
     );
    
     --Drop the fact_sale table if it already exists.
     DROP TABLE IF EXISTS [dbo].[fact_sale];
    
     --Create the fact_sale table.
    CREATE TABLE [dbo].[fact_sale]
    (
       [SaleKey] [bigint] NULL,
       [CityKey] [int] NULL,
       [CustomerKey] [int] NULL,
       [BillToCustomerKey] [int] NULL,
       [StockItemKey] [int] NULL,
       [InvoiceDateKey] [datetime2](6) NULL,
       [DeliveryDateKey] [datetime2](6) NULL,
       [SalespersonKey] [int] NULL,
       [WWIInvoiceID] [int] NULL,
       [Description] [varchar](8000) NULL,
       [Package] [varchar](8000) NULL,
       [Quantity] [int] NULL,
       [UnitPrice] [decimal](18, 2) NULL,
       [TaxRate] [decimal](18, 3) NULL,
       [TotalExcludingTax] [decimal](29, 2) NULL,
       [TaxAmount] [decimal](38, 6) NULL,
       [Profit] [decimal](18, 2) NULL,
       [TotalIncludingTax] [decimal](38, 6) NULL,
       [TotalDryItems] [int] NULL,
       [TotalChillerItems] [int] NULL,
       [LineageKey] [int] NULL,
       [Month] [int] NULL,
       [Year] [int] NULL,
       [Quarter] [int] NULL
    );
    
  5. To execute the query, on the query designer ribbon, select Run.

    Screenshot of the Run option on the query editor ribbon.

  6. Когда выполнение скрипта завершится, чтобы переименовать запрос, щелкните правой кнопкой мыши вкладку запроса и выберите Переименовать.

    Снимок экрана: опция

  7. In the Rename window, in the Name box, replace the default name with Create Tables.

    снимок экрана окна переименования с введенным именем скрипта.

  8. Выберите Переименовать.

  9. If necessary, in the Explorer pane, expand the Schemas folder, the dbo schema, and the Tables folder.

  10. Убедитесь, что перечислены две новые таблицы. The dimension_customer table was created in the previous tutorial.

    снимок экрана панели обозревателя, где можно найти таблицы и только что созданный запрос.

Next step