开发者社区> 问答> 正文

如何更好地在 SQL Server 中复制一组数据

如何更好地在 SQL Server 中复制一组数据

展开
收起
贺贺_ 2019-12-04 22:17:13 398 0
1 条回答
写回答
取消 提交回答
  • INSERT INTO BASKET(BASKETNAME)
    VALUES ('COPY BASKET')
    
    DECLARE @iBasketId int
    SET @iBasketId = @@SCOPE_IDENTITY;
    
    
    insert into Fruit (BasketId, FruitName)
    select @iBasketId, FruitName
    from Fruit 
    where BasketId = @originalBasket
    
    declare @tabFruit table (originalFruitId int, newFruitId int)
    
    insert into @tabFruit (originalFruitId, newFruitId)
    select o.FruitId, n.FruitId
    from (SELECT FruitId, FruitName from Fruit where BasketId = @originalBasket) as o
    join (SELECT FruitId, FruitName from Fruit where BasketId = @newBasket) as n
        on o.FruitName = n.FruitName
    
    
    insert into Property (FruitId, PropertyText)
    select NewFruitId, PropertyText
    from Fruit f join @tabFruit t on t.originalFruitId = f.FruitId
    
    2019-12-04 22:17:48
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
SQL Server在电子商务中的应用与实践 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载