-1

Why it's

select * from [User]

rather than:

select * from User

?

user1782784
  • 67
  • 1
  • 8

2 Answers2

4

Another reason : Square brackets mainly used to identify the column names with spaces or special characters in them. e.g. [movie name] However in that case, you must use brackets to refer to these columns then. So in order to give the universal idea to be able to use single name and multiple names for fields, the [] are always shown in the syntaxes.

This could be the same reason behind applying [] to table name as well.

According to this post: "" and [] are delimeter identifiers. This is necessary if the column name/table name is a reserved keyword or contains special characters such as a space or hyphen.

And this reference says User is a reserved keyword ...

You may want to try out with table name like myuser, to confirm if this nature still persists.

One other thing, if your book is an old version, where [] were optional in Visual studio for single table names. However it may have changed to the earlier versions of Visual stduio where you must use square brackets at times independent of table name being single name, two names, reserved word, name with special characters... :)

Community
  • 1
  • 1
bonCodigo
  • 14,268
  • 1
  • 48
  • 91
  • you are quite right, thanks! – user1782784 Dec 16 '12 at 16:56
  • @user1782784 I give you a +1, coz it was a valid question although we had to search for all the possible reasons that may have caused the error. :) the only issue, that you didn't articulated the question well, that is perhaps why it was closed :( – bonCodigo Dec 16 '12 at 17:01
1

I know where the problem is... table Name "Users" is ok instead of "User"

reference to: http://msdn.microsoft.com/en-us/library/aa224033(v=sql.80).aspx

user1782784
  • 67
  • 1
  • 8
  • I have mentioned that in my answer long ago ;) you may want to mark it as answered. So the system gets updated :) – bonCodigo Dec 16 '12 at 16:49