适用于:✅Microsoft Fabric 中的仓库
本教程介绍如何使用 T-SQL 在仓库中创建表。
创建表
在此任务中,了解如何使用 T-SQL 在仓库中创建表。
- 请确保在 第一个教程中创建的工作区 处于打开状态。 
- (从工作区登录页中列出的项列表中)选择 Wide World Importers 数据仓库。 
- 在“主页”功能区上,选择“新建 SQL 查询”。   
- 在查询编辑器中粘贴以下代码。 代码将删除 - 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 );
- 若要执行查询,请在查询设计器功能区上选择“运行”。   
- 脚本执行完成后,若要重命名查询,请右键单击查询选项卡,然后选择 重命名。   
- 在 重命名 窗口中,在 名称 框中,将默认名称替换为 - Create Tables。  
- 选择 重命名。 
- 如有必要,在 资源管理器 窗格中,展开 架构 文件夹、 - dbo架构和 表 文件夹。
- 验证是否列出了这两个新表。 - dimension_customer表是在 上一教程中创建的。