1

Possible Duplicate:
Incorrect syntax near the keyword 'User'

I'm trying to use very simple SQL query in SQL Server Management Studio 2008, the exact query is:

SELECT * FROM User;

But it gives me error when I try to run this.

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'User'.

This table exists and when I try to select any other table data with this statement (by replacing table name), I get all data as I want. Have anyone ideas how to repair it? Tried to google it, but didn't get answers.

3
  • 1
    SQL Server is decent about reporting this type of error (as opposed to MySQL) and gives hints here: "Incorrect syntax near the keyword 'User'". Commented May 15, 2012 at 15:29
  • 1
    A lot of times these errors can be avoided if you use plural names for tables. Since a table is a set of something, Users is better than User unless the intention is that the table will only ever hold one row. PS I'm not suggesting that is the solution, which is why I'm posting it as a comment. Commented May 15, 2012 at 15:30
  • 2
    Also it's great that we have six identical answers to this question. Anyone feel like withdrawing their answers to remove some noise? Commented May 15, 2012 at 15:31

6 Answers 6

9

User is a keyword. You will need to use an escape character. Try

SELECT * FROM [User]
Sign up to request clarification or add additional context in comments.

1 Comment

+1 You had the first answer ;)
3

User is a reserved word. You should use brackets []

SELECT * FROM [User]

Comments

2

Try this:

SELECT * FROM [User];

Comments

2

User is a reserved SQL keyword - try:

SELECT * FROM [User];

Comments

2

user is a reserved keyword , can you change the tname

Comments

2

"USER" is a SQL Server reserved keyword. You need to escape it:

SELECT * FROM [User];

Or:

SELECT * FROM "User";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.