我正在从一个数据库迁移到另一个数据库。
到目前为止一切正常但有一张桌子我总是得到同样的错误。我还想在此表中迁移外键存在问题。我想我必须为外键声明一些特别的东西吗?
这是我的疑问:
INSERT INTO [asd].HolidayTracker.dbo.AnnualVacation(UserId,WorkingTime,VacationDays,FromDate,ToDate)
SELECT u1.user_htUserId,
u1.vacationDays,
u1.workingTime,
CAST('2013-01-01' AS DATETIME),
CAST('2013-12-31' AS DATETIME)
FROM HolidayTracker.dbo.AnnualVacation u1
LEFT JOIN [asd].HolidayTracker.dbo.AnnualVacation u2
ON u1.user_htUserId = u2.UserId AND
u1.vacationDays = u2.VacationDays AND
u1.workingTime = u2.WorkingTime
这是我收到的错误消息:
error message INSERT INTO [asd].HolidayTracker.dbo.AnnualVacation(UserId,WorkingTime,VacationDays,FromDate,ToDate) – `
这是表结构: 来源表
目的地表
答案 0 :(得分:0)
对于初学者来说,与您选择的字段相比,您在insert语句中的WorkingTime,VacationDays字段是错误的。
尝试更改字段的顺序,如下所示,看看会发生什么。
错误可能就像你试图将浮点数插入int列而没有转换值一样简单。
INSERT INTO [asd].HolidayTracker.dbo.AnnualVacation(UserId,VacationDays,WorkingTime,FromDate,ToDate)
SELECT u1.user_htUserId,
u1.vacationDays,
u1.workingTime,
CAST('2013-01-01' AS DATETIME),
CAST('2013-12-31' AS DATETIME)
FROM HolidayTracker.dbo.AnnualVacation u1
LEFT JOIN [asd].HolidayTracker.dbo.AnnualVacation u2
ON u1.user_htUserId = u2.UserId AND
u1.vacationDays = u2.VacationDays AND
u1.workingTime = u2.WorkingTime