我有两个表具有相同的列,除了一个是userId。我想将第一个表中的所有数据复制到第二个表中,并将自定义userId添加到缺少的列中。到目前为止还没有成功。
查询如下所示。插入Quality、Quantity、Supplier和UserId (在获取数据的表中不存在)
`DECLARE @UserId int = 5611; -- add this to all the data from dbo.GasStation
INSERT INTO dbo.NewGasStation (Quality, Quantity, Supplier, UserId)
SELECT * FROM dbo.GasStation -- UserId doesn't exist in this table
-- Add somehow @UserId to all the data i'm getting from GasStation in order to satisfy the column UserId in the NewGasStation`我从dbo.GasStation获得的所有数据都要插入到dbo.NewGasStation中,并将这个自定义UserId添加到所有结果中。
发布于 2019-05-28 19:54:10
如果只想复制所有列,也不需要区分列。只需使用*即可。
如下所示:
DECLARE @UserId integer = 5611;
INSERT INTO [Target]
SELECT *, @UserId FROM [Source]https://stackoverflow.com/questions/56341402
复制相似问题