扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Vaughn Washington 来源:code-magazine 2007年11月19日
关键字: SQL Server 2008 SQL Server 数据库
New Building Blocks: New and Enhanced Date & Time Types
In previous releases of SQL Server, the database exposed date and time data primarily through two data types: DATETIME and SMALLDATETIME (Table 1). In SQL Server 2005, these types began to show their age and developers began to bump into their limitations.
You can break down problems with the existing date/time types into five categories:
In order to address these problems, SQL Server 2008 introduces support for four new types: DATE, TIME, DATETIME2, and DATETIMEOFFSET; along with a rich set of built-in T-SQL function support for the new types:
As you can see, all new types support a broader range, and where appropriate, user-defined, fractional-second precision (Table 2). This allows developers to tune the storage size of columns to exactly fit application needs, which for large databases, translates to significant savings in storage costs. Now let me discuss how data access stacks expose these types.
" |
All new types support a broader range, and where appropriate, user-defined, fractional-second precision. This translates to developers being able to tune the storage size of columns to exactly fit application needs, which for large databases, translates to significant savings in storage costs. |
" |
The new SQL Server types DATE and DATETIME2 correlate to existing types in all data access technologies. For ADO.NET this is DateTime for both, for ODBC it’s SQL_DATE and SQL_TIMESTAMP respectively, and for OLE DB it’s DBTYPE_DBDATE and DBTYPE_DBTIMESTAMP. The new SQL types TIME and DATETIMEOFFSET were more difficult to express in some cases because the conceptual type didn’t already exist. While you could map TIME to TimeSpan in ADO.NET, Microsoft needed to invent new provider types in ODBC and OLE DB (SQL_SS_TIME2 and DBTYPE_DBTIME2) because existing types don’t support fractional-second precision. As you’d guess, these match their pre-existing types in every way with the addition of a fraction component matching the component that already exists in SQL_TIMESTAMP/DBTYPE_DBTIMESTAMP. The server type DATETIMEOFFSET is unique in that, in addition to containing all date/time parts of other types, it also includes a time-zone offset. To accommodate this type, Microsoft introduced new types across the board. The .NET Framework 3.5 release includes a new system type conveniently named DateTimeOffset while OBDC and OLE DB introduce SQL_TIMESTAMPOFFSET and DBTYPE_DBTIMESTAMPOFFSET; all of which should look familiar to people used to working with their non-time-zone-aware equivalents. These new types are first-class citizens in every way-with the goal of being better data-type alternatives for new application development and replacement options for application enhancements. In addition to introducing new data types and programming constructs, SQL Server 2008 also removes limitations on existing types to open the door to new application scenarios.
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者