SQL Server 中的 DATE 类型问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1685026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problem with DATE type in SQL Server
提问by Brian Koser
I'm trying to CREATE a TABLE with an attribute of type DATE in Microsoft SQL Server 2008. However, when I execute the query,
我正在尝试在 Microsoft SQL Server 2008 中创建一个具有 DATE 类型属性的 TABLE。但是,当我执行查询时,
I get the error:
我收到错误:
Column, parameter, or variable #3: Cannot find data type DATE.
I consulted the documentation, and it indicated that DATE is a valid type in SQL Server. It works if I replace "DATE" with "DATETIME". My guess is I'm missing something really simple, but I just started learning SQL and SQL Server; does anybody have an idea?
我查阅了文档,它表明 DATE 是 SQL Server 中的有效类型。如果我用“日期时间”替换“日期”,它会起作用。我的猜测是我错过了一些非常简单的东西,但我刚刚开始学习 SQL 和 SQL Server;有人有想法吗?
回答by ron
If you really want to use DATE, you could change the compatibility level of the database.
如果你真的想使用 DATE,你可以改变数据库的兼容级别。
ALTER DATABASE dbname SET COMPATIBILITY_LEVEL = 100
That would switch the database to 2008 compatibility, and you should be able to use the DATE datatype.
这会将数据库切换到 2008 兼容性,您应该能够使用 DATE 数据类型。
回答by Alex_L
It is possible that your database is 8.0 or 9.0 compatible. In this case you cannot use DATE type.
您的数据库可能与 8.0 或 9.0 兼容。在这种情况下,您不能使用 DATE 类型。