当我尝试为SQL Server 2005版生成架构和数据时,在我的SQL 2008 R2中保存或发布脚本向导会出现以下错误。
错误讯息:
Microsoft.SqlServer.Management.Smo.SmoException:对象ExamAttempt中的列RemainingTime包含类型Time,目标服务器版本不支持SQL Server 2005.在Microsoft.SqlServer.Management.SqlScriptPublish.GeneratePublishPage.worker_DoWork(Object发件人,DoWorkEventArgs e)位于System.ComponentModel.BackgroundWorker.WorkerThreadStart(对象参数)的System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
SQL 2005中的Time类型是否有替代方法???
答案 0 :(得分:0)
我只想使用日期时间来存储每个单元。这样做可确保您将来能够使用所有本机日期时间函数来搜索或操作此数据。如果您选择升级2005 db,您还可以在以后轻松转发到离散数据类型。
在下面的示例中,了解如何使用检查约束提供一些数据类型完整性。
declare @time time = '10:30',
@date date = '01/01/2001';
select [theTime] = cast(@time as datetime),
[theDate] = cast(@date as datetime),
[theDateTime] = cast(@time as datetime) + cast(@date as datetime);
declare @t table (theDate datetime check(dateAdd(dd,datediff(dd,0,theDate),0) = theDate), theTime datetime check(datediff(dd,0,theTime) = 0))
-- succeeds, since you didnt supply date in the time only column
insert into @t
values(cast('01/01/2001' as datetime), cast('10:30' as datetime));
-- fails, since you passed date with the expected time only value
insert into @t
values(cast('01/01/2001' as datetime), cast('01/01/2001 10:30' as datetime));
-- fails, since you passed time with expected date only value
insert into @t
values(cast('01/01/2001 10:30' as datetime), cast('10:30' as datetime));