sql - 使用日期格式将值简单地插入表中
问题描述
我正在尝试将一些基本数据插入表中,但我不断收到错误消息。起初,我以为我只是在插入日期列时的日期格式不正确,但现在我在猜测。
最初,第 4 列的日期格式为 12-Jan-10 的数据类型DATE
。我已将格式更改为 2010-01-12 但我仍然收到相同的错误。我可能在这里遗漏了一些简单的东西,但我不太确定它是什么。
我得到的错误是
消息 241,级别 16,状态 1,第 2 行
从字符串转换日期和/或时间时转换失败。
这是表格的列...
BookName (PK, Varchar(45), not null)
Genre (varchar(25), not null)
DateOfPublication (date,not null)
NoOfPages (int, not null)
WriterID (PK, FK, varchar(11), not null)
EditorID (FK, varchar(11), not null)
insert into BOOK (BookName, Genre, DateOfPublication, NoOfPages, WriterID, EditorID)
values ('Valley of Heroes','10','Fiction','2010-01-12',874,'20');
insert into BOOK (BookName, genre, DateOfPublication, NoOfPages, WriterID, EditorID)
values ('The Ruler''s Return','11','Fantasy','2012-03-14',765,'22');
insert into BOOK (BookName, genre, DateOfPublication, NoOfPages, WriterID, EditorID)
values ('eRobot','11','Fantasy','2011-04-15',264,'20');
insert into BOOK (BookName, genre, DateOfPublication, NoOfPages, WriterID, EditorID)
values ('An Uncle''s Letters','12','Fiction','2012-06-12',258,'20');
insert into BOOK (BookName, genre, DateOfPublication, NoOfPages, WriterID, EditorID)
values ('Pretty flowers','13','Album','2013-01-31',148,'22');
insert into BOOK (BookName, genre, DateOfPublication, NoOfPages, WriterID, EditorID)
values ('A Tale of Lions','12','Fantasy','2012-08-17',301,'21');
insert into BOOK (BookName, genre, DateOfPublication, NoOfPages, WriterID, EditorID)
values ('eRobot','13','Sci Fi','2012-10-04',465,'23');
解决方案
执行insert
. _ 列名和值的顺序必须相同:
insert into book (BookName, WriterID, Genre, DateOfPublication, , NoOfPages, EditorID)
values ('Valley of Heroes', '10', 'Fiction', '2010-01-12', 874, '20');
推荐阅读
- javascript - 使用 NODEJS HTTPS 将 JSON 数据发送到服务器
- macros - 球拍扩展了引用列表形式的宏
- sql - 通过列的最新值以及其他谓词查找
- kubernetes - 如何将 nodeSelector 添加到部署 yaml 文件?
- c - CMake:不同平台的多个可执行文件共享通用代码
- pyspark - Databricks 中的 Snappy 压缩和解压缩
- javascript - 使用 Javascript 关闭 IOS 原生选择框菜单
- python - 如何在 Python3 中显示一个非常大的数字的所有数字
- python - pandas:如何在 python 中将数据写入 csv 文件
- python - 获取所有列条目都为空的 groupby 数据框