Sql Server 2005 中的时间数据类型 [英] Time DataType in Sql Server 2005

查看:30
本文介绍了Sql Server 2005 中的时间数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SQL Server 2008 下创建了小型数据库.现在我想将它移到 SQL Server 2005 并且它不起作用,因为它没有 Time 数据类型.我必须在 SQL Server 2005 中仅存储时间的选项是什么.我编写了小型 TimeSheet 应用程序,它需要以 05:30:00 (hh:mm:ss) 等格式编写小时和分钟,但 ss 是可选的.

I've created small database under SQL Server 2008. Now i wanted to move it to SQL Server 2005 and it doesn't work since it doesn't have Time datatype. What option do I have to store only time in SQL Server 2005. I've written small TimeSheet application which needs to write hours and minutes mostly in format like 05:30:00 (hh:mm:ss) but ss is optional.

推荐答案

SQL Server 2005 确实支持 DATETIME 数据类型,其中也包括时间.要仅存储时间,可以使用 CONVERT 语句:

SQL Server 2005 does support the DATETIME datatype, which also includes time. To store only the time, you can use the CONVERT statement:

SELECT CONVERT(DATETIME, '11:22:33')

不是最优的,因为日期部分没有使用,但仍然占用存储空间.但话又说回来,将数据库降级到以前的版本从来都不是最佳选择.

It's not optimal, because the date part is not used, but still takes up storage space. But then again, downgrading a database to a previous version never is optimal.

这篇关于Sql Server 2005 中的时间数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆