问题描述
OLTP名为FYP项目
名为FYPStarSchema的数据仓库
一旦我有了加载数据仓库,我想再次加载它但是它给出了违反主键的错误(不允许复制)
插入Product_Dimension(Product_key,Product_Name,Product_Colour,Sale_Price,Cost_Price)
SELECT P_ID,articleNO,颜色,Cur_Sale_Price,CostPrice
来自[FYP项目] .dbo.Product
从Product_Dimension中选择max(Product_key)
int a = max(Product_key )
其中Product_key> a
SELECT MAX(Product_key)AS FROM FROM Product_Dimension WHERE Product_key>最大的
select * from Product_Dimension
OLTP named FYP Project
Data Warehouse named FYPStarSchema
Once i have load data warehouse now i want to load it again but it give an error of violation of primary key(duplication cannot be allowed)
Insert Into Product_Dimension(Product_key,Product_Name,Product_Colour,Sale_Price,Cost_Price)
SELECT P_ID, articleNO, colour, Cur_Sale_Price, CostPrice
FROM [FYP Project].dbo.Product
select max(Product_key) from Product_Dimension
int a=max(Product_key)
where Product_key>a
SELECT MAX(Product_key) AS largest FROM Product_Dimension WHERE Product_key > largest
select * from Product_Dimension
推荐答案
SELECT MAX(column) AS largest FROM table WHERE column > largest
这显然是愚蠢的 - 它不能返回任何大于最大值的记录,因为如果记录大于最大记录,它将是最大的!悖论,我很害怕。
如果你想返回一列中的最大值那么就这样做:
Which is clearly silly - it can''t return any records that are larger than the largest value, because if a record was larger than the largest, it would be the largest! Paradox, I''m afraid.
If you want to return the largest value in a column then just do that:
SELECT MAX(Product_Key) FROM Product_Dimension
这将返回单个值,表中最大的值。
That will return a single value, the largest in the table.
这篇关于如何在SQL Server 2005中获取最大ID并将其存储在int中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!