【问题标题】:Error in generating schema with data for SQL Server 2005 from SQL Server 2008 R2使用 SQL Server 2008 R2 中的 SQL Server 2005 数据生成架构时出错
【发布时间】:2012-08-21 02:19:35
【问题描述】:

当我尝试为 SQL Server 2005 版生成架构和数据时,在我的 SQL 2008 R2 中保存或发布脚本向导出现以下错误。

错误信息:

Microsoft.SqlServer.Management.Smo.SmoException:对象 ExamAttempt 中的列 RemainingTime 包含类型 Time,在 Microsoft.SqlServer.Management.SqlScriptPublish.GeneratePublishPage.worker_DoWork(Object发送者,DoWorkEventArgs e) 在 System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) 在 System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

SQL 2005 中的 Time 类型有什么替代方法吗???

【问题讨论】:

    标签: sql-server-2008-r2


    【解决方案1】:

    我只会使用日期时间来存储每个单元。这样做可确保您将来能够使用所有本机日期时间函数来搜索或操作这些数据。如果您选择升级 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));
    

    【讨论】:

      猜你喜欢
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 2015-08-07
      • 2013-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多