insert into ProductSpec(ProductId,Value,Price) select id,'红色',15.00 union all select id,'蓝宝石色',15.50 union all ...
[其他解释] union all起来,批量写入. [其他解释] 规格是自己定,你不一个一个写进去,数据库能自己生出来不成。 [其他解释] 是这个意思么?
--把发卡的价格都涨1元 update ProductSpec a set a.price=(case a.商品规格 when '红色' then '16.00' when '宝蓝' then '16.00' when '绿宝' then '16.50' when '粉色' then '16.00' end ) from Product b where a.ProductId=b.id and b.name='发卡'
[其他解释] 是想批量新增。 我现在是这样的写法 1. insert into Product(name) values('发卡') 返回id=@@IDENTITY 2.然后再一句句向表中写 insert into ProductSpec(ProductId,Value,Price) Values(id,'红色',15.00) insert into ProductSpec(ProductId,Value,Price) Values(id,'蓝宝石色',15.50) insert into ProductSpec(ProductId,Value,Price) Values(id,'绿宝石色',15.50) insert into ProductSpec(ProductId,Value,Price) Values(id,'粉色',15.00) insert into ProductSpec(ProductId,Value,Price) Values(id,'黄色',15.20) insert into ProductSpec(ProductId,Value,Price) Values(id,'黑色',14.50) [其他解释] 总觉得这种写法,麻烦并且效率有点低。有没有更好的写法? [其他解释] +1