使用标识迁移master - detail结构化表数据

时间:2015-07-29 09:03:11

标签: sql sql-server identity

如何迁移主详细信息表数据? 主表中有一个标识。

APPOINTMENT - 主表(使用AppointmentSeq密钥标识)

APPOINTMENT_ITEM - 明细表

我尝试过如下但失败了。

INSERT INTO dbo.APPOINTMENT ([AppointmentNumber]
  ,[AppointmentDate]
  ,[AppointmentEndDate]
  ,[AppointmentTime]
  ,[AppointmentEndTime]
  ,[UserID])
SELECT [AppointmentNumber]
  ,[AppointmentDate]
  ,[AppointmentEndDate]
  ,[AppointmentTime]
  ,[AppointmentEndTime]
  ,UserID
FROM DB1.dbo.APPOINTMENT 

DECLARE @lastident AS int
SET @lastident = @@IDENTITY

INSERT INTO [dbo].[APPOINTMENT_ITEM]
SELECT @lastident
  ,a.AppointmentNumber
  ,a.AppointmentDate
FROM DB1.dbo.APPOINTMENT_ITEM a
INNER JOIN DB1.dbo.APPOINTMENT b
     ON a.AppointmentSEQ = b.AppointmentSEQ

1 个答案:

答案 0 :(得分:1)

我会保留旧数据库中的标识值!你只需要将var height = document.documentElement.offsetHeight; if(document.all) height = Number(document.body.clientHeight) + Number(document.body.bottomMargin) + Number(document.body.topMargin); // IE v <= 10 设置为开启,就可以了。希望这个例子有所帮助:

IDENTITY_INSERT