Click here to Skip to main content
16,015,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,
I have renamed a table in sql server from Project to Order.
Now when I fire 'select * from Order' it gives error - 'Incorrect syntax near Order' .

I am using sql server 2008 r2.

Please help.
Posted

That is because "Order" is a reserved word (used when querying "order by"). So you have to do as OriginalGriff says. Put [] around it. You will see it in tou query editorwhen you write a reserved word. It turns blue (at least by default)

SQL
SELECT * FROM [Order]


Here is a list over all reserved words in sql: http://drupal.org/node/141051[^]

It's a good practice to avoid naming your tables with names from this list..
 
Share this answer
 
Comments
bbirajdar 19-Jul-12 11:05am    
Correct answer.. +5
tarik shaikh 20-Jul-12 1:39am    
Thank you very much.
Simple: "ORDER" is an SQL reserved word. Either don't use it for your table name (try "Orders" instead, tables are normally plural) or enclose it in square brackets:
SQL
SELECT * FROM [Order]
 
Share this answer
 
Comments
StianSandberg 19-Jul-12 10:52am    
5'ed..
bbirajdar 19-Jul-12 11:04am    
exactly... +5
tarik shaikh 20-Jul-12 1:38am    
Thanks a lot!!!
OriginalGriff 20-Jul-12 3:07am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900