Applies to:✅ Warehouse in Microsoft Fabric
在本教學課程中,瞭解如何使用 T-SQL 在倉儲中建立數據表。
Note
This tutorial forms part of an end-to-end scenario. 若要完成本教學課程,您必須先完成下列教學課程:
建立數據表
在這項工作中,瞭解如何使用 T-SQL 在倉儲中建立數據表。
Ensure that the workspace you created in the first tutorial is open.
Select the Wide World Importers warehouse (from the items listed on the workspace landing page).
On the Home ribbon, select New SQL query.
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 );
To execute the query, on the query designer ribbon, select Run.
當文稿執行完成時,若要重新命名查詢,請在 [查詢] 索引標籤上按下滑鼠右鍵,然後選取 [重新命名。
在 [重新命名] 視窗中,於 [名稱] 方塊中,將預設名稱取代為
Create Tables
。選擇 重新命名。
如有必要,請在 [總管] 窗格中,展開 [架構] 資料夾、[
dbo
架構] 和 [數據表] 資料夾。確認已列出兩個新的數據表。
dimension_customer
數據表是在 上一個教學課程中建立的。