我的SQL代码无效我的代码应该是正确的,我会受到0行的影响。
use CA
truncate table salesFacts
INSERT INTO CA..salesFacts
(date,customerNumber,productCode,orderNumber,productLine,price,quantity)
SELECT
replace(CONVERT(DATE,o.OrderDate, 112),'-',''),
c.customerNumber,
pr.productCode,
o.orderNumber,
pl.productLine,
od.priceEach,
od.quantityOrdered
FROM
CA..orders o,
CA..products pr,
CA..customers c,
CA..orderDetails od,
CA..productLines pl
WHERE
o.customerNumber = c.customerNumber
AND od.productCode = pr.productCode
AND od.orderNumber = o.orderNumber
AND pr.productLine = pl.productLine
这是它的表格:
CREATE TABLE salesFacts (
date Datetime NOT NULL,
customerNumber int NOT NULL,
productCode varchar(15) NOT NULL,
orderNumber int NOT NULL,
productLine varchar(50) NOT NULL,
price decimal(6,2) NOT NULL,
quantity INT NOT NULL,
primary key(customerNumber, productCode, orderNumber, productLine),
foreign key (customerNumber) references Customers (customerNumber),
foreign key(productCode) references products(productCode),
foreign key (orderNumber) references orders(orderNumber),
foreign key (productLine) references productLines(productLine))
非常感谢您的帮助。几个小时我一直在使用这段代码,但仍然无法做到。任何帮助将不胜感激