Question

I have a database called Inspection, and a table called User.

I first try to query it as follows:

select * from User ;

... and then like this:

select * from Inspection.dbo.User ;

Both of these are throwing the following error:

Incorrect syntax near the keyword 'User'

Why am I getting this error?

Was it helpful?

Solution

You need to use square brackets around the name of the table, since you use the name user.

Since user is a reserved word (has a special meaning on it's own), it can not be used directly as a table-name.

The square brackets tells MS Sql that in this case, [user] is the name of something a user (you!) have defined (namely a table), and not a keyword in an operation on an actual user, as in for example:

CREATE USER slartibartfast (...);

Update: More info about this here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top