为什么这个非常简单的SQL查询在MS Access中失败?

为什么这个非常简单的SQL查询在MS Access中失败?

问题描述:

我有一个疑问,即所有权利都不会失败,而且我一生无法弄清楚原因

I have a query that by all rights should not possibly fail, and I can't for the life of me figure out why

INSERT INTO Grocery_Store_Prices(Store,Item,Brand,Price,Unit,Quantity,Note) 
VALUES("Kroger","Cheesy Poof","Cartman",0.51,"fart",15,"what is going on");

当我尝试运行查询时,出现"INSERT INTO语句中的语法错误",其中注释"字段突出显示.如果我忽略注释"字段及其值,则查询工作正常.是我真的很想念某些东西,还是这里隐藏了一个Jet SQL怪癖??

When I try to run the query I get "Syntax error in INSERT INTO statement" with the Note field highlighted. If I omit the Note field and its value, the query works fine. Is there something really obvious I'm missing, or is there an Jet SQL quirk buried here???

它作用于的表是: Grocery_Store_Prices

The table it's acting on is: Grocery_Store_Prices

  • ID-自动编号主键
  • 商店-文字
  • 日期-日期/时间
  • 项目-文本
  • 品牌-文字
  • 价格-货币
  • 单位-文本
  • 数量-数量(两倍)
  • 注意-文本.

注释"是Microsoft Access中的保留字.您需要用方括号将其包围:

"Note" is a reserved word in Microsoft Access. You need to surround it with square brackets:

INSERT INTO Grocery_Store_Prices(Store,Item,Brand,Price,Unit,Quantity,[Note])
VALUES("Kroger","Cheesy Poof","Cartman",0.51,"fart",15,"what the ____");

此处保留字的有用列表: http://support.microsoft.com/kb/286335

Helpful list of reserved words here: http://support.microsoft.com/kb/286335

有些人认为最好始终将 字段名称括在方括号中,以免您不必担心.

Some consider it best practice to always encase field names in square brackets, just so you don't have to worry about it.

祝你好运!