Using the TIME data type in SQL Server 2008
2008-03-07 10:48
656 查看
SQL Server 2008 introduces a TIME data type which allows us to store the time without the date.
An example of using this is:
DECLARE @t TIME = '17:32:19'
SELECT [Time] = @t
- - - - - - - - - - - - - - - - -
Time
----------------
17:32:19.0000000
This example also shows how you can assign a value in the DECLARE statement. The default accuracy is 100 nanoseconds. The TIME data type also allows you to define the accuracy. This indicates how many places to the right of the decimal are stored for the seconds portion.
You can define from zero to seven places to the right of the decimal. A TIME(0) takes three bytes to store and a TIME(7) takes five bytes to store. Declaring an accuracy of three or four would take four bytes to store. If you declare a TIME variable without the accuracy it defaults to TIME(7).
TIME will do an implicit conversion from DATETIME and retain only the time portion. TIME will implicitly accept strings in most common time formats.
TIME doesn't include any information on the time zone. It will accept a time with time zone information but will ignore the time zone.
The TIME datatype is fairly straightforward and very small for the information stored. It should come in very handy.
From:http://www.sqlteam.com/article/using-the-time-data-type-in-sql-server-2008
An example of using this is:
DECLARE @t TIME = '17:32:19'
SELECT [Time] = @t
- - - - - - - - - - - - - - - - -
Time
----------------
17:32:19.0000000
This example also shows how you can assign a value in the DECLARE statement. The default accuracy is 100 nanoseconds. The TIME data type also allows you to define the accuracy. This indicates how many places to the right of the decimal are stored for the seconds portion.
DECLARE @t0 TIME(0) = '17:32:19.1234567', @t7 TIME(7) = '17:32:19.1234567' SELECT [Time0] = @t0, [Time7] = @t7 - - - - - - - - - - - - - - - - - Time0 Time7 -------- ---------------- 17:32:19 17:32:19.1234567
You can define from zero to seven places to the right of the decimal. A TIME(0) takes three bytes to store and a TIME(7) takes five bytes to store. Declaring an accuracy of three or four would take four bytes to store. If you declare a TIME variable without the accuracy it defaults to TIME(7).
TIME will do an implicit conversion from DATETIME and retain only the time portion. TIME will implicitly accept strings in most common time formats.
DECLARE @d1 DATETIME = '12/19/2007 13:43:23.45', @t1 TIME(2) SELECT @t1 = @d1 SELECT TimeOnly = @t1 - - - - - - - - - - - - - - - - - TimeOnly ----------- 13:43:23.45
TIME doesn't include any information on the time zone. It will accept a time with time zone information but will ignore the time zone.
DECLARE @t1 TIME(0) = '13:45:12 -05:00' SELECT [Time] = @t1 - - - - - - - - - - - - - - - - - Time -------- 13:45:12
The TIME datatype is fairly straightforward and very small for the information stored. It should come in very handy.
From:http://www.sqlteam.com/article/using-the-time-data-type-in-sql-server-2008
相关文章推荐
- Error: The version of SQL Server in use does not support datatype 'datetime2'
- ?? [SQL Server] -- Using FILESTREAM to Store BLOBs in the NTFS File System in SQL Server 2008
- Could not store transport type data for Receive Location 'Recv.Loc' to config store. Primary SSO Server 'Sql-server' failed. The external credentials in the SSO database are more recent.
- How to select the data type in SQLserver database such as varchar, nvarchar
- ADO.NET Entity Framework: The version of SQL Server in use does not support datatype 'datetime2'
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- Using MERGE in SQL Server to insert, update and delete at the same time
- ERROR: The version of SQL Server in use does not support datatype 'datetime2'.
- 海洋工作室——网站建设专家:The version of SQL Server in use does not support datatype datetime2 and the Entity Framework.
- Renaming the Physical Filename for Datafiles in SQL Server 2008
- Error: The version of SQL Server in use does not support datatype 'datetime2
- Create maintenance backup plan in SQL Server 2008 R2 using the wizard
- The version of SQL Server in use does not support datatype 'datetime2'.
- JAVA+ Proxool+ SQLserver 2008 “signer information does not match signer information of other classes in the same package”
- Using SOAP Interface with the SQL Server Data Services
- [MSSQL2008]Spatial Data in SQL Server 2008 - 根据经纬度计算两点间距离
- Work with XML Data Type in SQL Server 2005 from ADO.NET 2.0
- [转]Using the Microsoft Connector for Oracle by Attunity with SQL Server 2008 Integration Services
- Get XML tree format based on the tree data in SQL server table
- Where is the Surface Area Configuration tool in SQL Server 2008