简体   繁体   English

使用简单查询的SQL错误

[英]SQL Error with a simple Query

Im building an application but then learned we needed to use sql database and im getting this returned now and unsure why? 我正在构建一个应用程序,但随后了解到我们需要使用sql数据库,并立即获取此信息,不确定为什么吗?

SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near the keyword 'User'. SQLSTATE [42000]:[Microsoft] [SQL Server的ODBC驱动程序11] [SQL Server]关键字“用户”附近的语法不正确。

Query: 查询:

SELECT *
FROM User WHERE (username = 'james' OR email = 'james') AND password =
'M4erz2BE/N7NYyE40UJRo5W1E1ZiqKpOMWQhm+R8Esc='

Make sure you're querying the correct database and that the [User] table is defined in the default schema. 确保查询的数据库正确,并且[User]表在默认架构中定义。 Else you'll need to explicitly specify the schema before the table name. 否则,您需要在表名之前显式指定架构。

Also when you use identifiers (Column, table or database names) adjust yourself to surrounding those with brackets. 同样,当您使用标识符(列,表或数据库名称)时,请调整自己以使其包含在方括号内。 It makes the query more readable: 它使查询更具可读性:

SELECT *
FROM [dbo].[User] WHERE ([username] = 'james' OR [email] = 'james') AND [password] =
'M4erz2BE/N7NYyE40UJRo5W1E1ZiqKpOMWQhm+R8Esc='

You are likely using the wrong database. 您可能使用了错误的数据库。 Either specify the database name in your connection string, or fully qualify your table name. 在连接字符串中指定数据库名称,或完全限定表名称。

Also, "User" is a reserved word . 另外,“用户”是保留字 Change your query to this: 将查询更改为此:

SELECT * FROM yourDatabaseName.dbo.[User] WHERE (username = 'james' OR email = 'james') AND password = 'M4erz2BE/N7NYyE40UJRo5W1E1ZiqKpOMWQhm+R8Esc='

Try this to select user, not sure but give it a try 尝试此操作以选择用户,不确定但尝试一下

      SELECT user 
      WHERE username = 'james' OR email = 'james'
      AND password ='M4erz2BE/N7NYyE40UJRo5W1E1ZiqKpOMWQhm+R8Esc='

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM