Are you getting an error with what should be good SQL?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
ReverendDexter
Forum Contributor
Posts: 193
Joined: Tue May 29, 2007 1:26 pm
Location: Chico, CA

Are you getting an error with what should be good SQL?

Post by ReverendDexter »

I've noticed that about 1 out of every 10 post here are errors that are good SQL that just happens to fail because of the use a reserved word. So, if you know your SQL should be good, check this:

http://dev.mysql.com/doc/refman/5.0/en/ ... words.html

I apologize if this is already posted/obvious/unecessary, just seemed to be seeing it a lot lately.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

.. which is why you should always wrap your table and column names in backticks to avoid current (and future) reserved name collisions :wink:
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Jcart wrote:.. which is why you should always wrap your table and column names in backticks to avoid current (and future) reserved name collisions :wink:
No, you should avoid reserved words period. The backtick is a way to cover poor SQL coding practices. Also, if you are writing portable SQL code backticks are not supported by all SQL database systems.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

AKA Panama Jack wrote:
Jcart wrote:.. which is why you should always wrap your table and column names in backticks to avoid current (and future) reserved name collisions :wink:
No, you should avoid reserved words period. The backtick is a way to cover poor SQL coding practices. Also, if you are writing portable SQL code backticks are not supported by all SQL database systems.
I would beg to differ. It is impossible to know any future reserved words collisions. Better safe than sorry.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Jcart wrote:I would beg to differ. It is impossible to know any future reserved words collisions. Better safe than sorry.
That is backward compatibility for.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

AKA Panama Jack wrote:No, you should avoid reserved words period.
What for? They are generally descriptive.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

I tend to agree with avoiding use of reserved words. With a "good", meaningful naming scheme you are unlikely to have conflicts including in the future. It has often come to my attention that often we try to shorten things uneccessarily to make it easier for us to type queries. In reality this might make life easier in the short term but makes the code and logic far less maintainable in the long run. After all how many of us actually comment our tables or document our databases properly ? I say this knowing it is something I normally "skip".
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Ok have to also say that having a list of reserved words is useful... Here are some quick link I found by using a favourite search engine...

postgres
Sql Server
Oracle
A utility which may be useful
Post Reply