我如何使用“日期"sql server 中的数据类型?

How Can I use quot;Datequot; Datatype in sql server?(我如何使用“日期sql server 中的数据类型?)
本文介绍了我如何使用“日期"sql server 中的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,我需要你的帮助,当我尝试在表中创建数据类型为Date"的列时,它给了我错误,我无法在此处添加它,这是我的代码

Hello Friends I need your help please when I'm trying to create column in table with data type "Date" it gives me error and I can't add it here is my code

Create table Orders (
Order_ID INT Primary Key,
Book_name varchar(100) ,
isbn varchar(100) ,
Customer_ID INT Foreign key references Customer,
Order_date date,
);

另一件事它需要我来获取创建之前的东西的日期

another thing it requires from me to get date of something which is before created one

更清楚:询问的查询表明要在 8 月 2 日之前找到日期我该怎么做

to be more clear: the query asked indicates to find date before 2 of August How can I do that

我尝试输入这样的数据

Insert Into Orders(Order_ID, Book_name, isbn, Customer_ID, Order_date) values (1, 'Design User Interface',9345678210123, 1, '02-08-2015'); 
Insert Into Orders(Order_ID, Book_name, isbn, Customer_ID, Order_date) values (2, 'Fire',9654693261489, 1, '05-08-2015'); 
Insert Into Orders(Order_ID, Book_name, isbn, Customer_ID, Order_date) values (3, 'The Odyssey',9654864332511, 2, '01-08-2015'); 
Insert Into Orders(Order_ID, Book_name, isbn, Customer_ID, Order_date) values (4, 'Anatomy',9654877777755, 2, '30-07-2015'); 
Insert Into Orders(Order_ID, Book_name, isbn, Customer_ID, Order_date) values (5, 'Surgery',9654864951753, 2, '01-07-2015'); 

但是,它只接受前 3 个插入和后两个它给我错误:/

but, it accept only first 3 insertion and last two it gives me error :/

推荐答案

最后两个"你没有问题.

You do not have a problem with the "last two".

但是,您确实对所有这些都存在问题,但是一点一点.

However, you do have a problem with all of them, but one point after the other.

您的日期被解释为 MM-DD-YYYY.这种解释取决于您系统的文化.前三个正在变成错误的日期,但有效.第 4 次中断,第 5 次从未执行(由于之前的错误).

Your dates are interpreted as MM-DD-YYYY. This intrepretation is depenent on your system's culture. The first three are turning into wrong dates but work. The 4th breaks and the fifth is never executed (due to the error before).

所以实际的错误在于第 4 行.

So the actual error lies on line 4.

无论何时处理日期,都应使用独立于文化的格式.最好使用以下任一方式-

Whenever you deal with dates, use culture independent formats. It is better to use either of the following-

20150730 (=> the 30th of July in 2015)

ODBC格式

{d'2015-07-30'} or {t'23:30:59'} or {ts'2015-07-30 23:30:59'}

ISO8601

'2015-07-30T00:00:00'

这篇关于我如何使用“日期"sql server 中的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)