【发布时间】:2019-08-28 18:42:49
【问题描述】:
我已恢复 AdventureworksDW2012 并尝试在以 Adventureworks 作为我的来源创建的新数据库中创建事实表。当我运行以下脚本时,我收到一条错误消息,指出违反了主键:
我尝试过使用 DISTINCT 函数,但不起作用
INSERT INTO dbo.InternetSales
(SalesOrderNumber, ProductKey, DateKey,
OrderQuantity, SalesAmount,
UnitPrice, DiscountAmount, PromotionKey)
SELECT DISTINCT SalesOrderNumber as SalesOrderNumber,
ProductKey, OrderDateKey as DateKey,
OrderQuantity, SalesAmount,
UnitPrice, DiscountAmount, PromotionKey
FROM AdventureWorksDW2012.dbo.FactInternetSales
;
GO
我希望能够在我的新数据库中创建 AdventureWorks 中的 FactInternetSales 表
【问题讨论】:
-
为
InternetSales添加表创建脚本 -
你的主键是什么?我的猜测是您正在尝试为主键插入重复值。
-
右击表>脚本表为>创建到....
标签: sql sql-server sql-insert