LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2008, 08:52 AM   #1
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
MySQL: Trying to Drop Columns Named update and delete


I've recently transferred several Jet ("Access") databases to MySQL. I'm cleaning up the tables and have run into a problem. Some of the tables have columns named update and delete. Unfortunately with those names being SQL keywords, I get SQL syntax errors when I try to do anything with those columns.

I've looked throught the MySQL Reference Manual and Googled, but haven't found anything that seems to address my issue. I'm not sure I'm providing Google with very good search phrases either. All I really want to do is drop the update and delete columns from the table. Any pointers appreciated!

TIA
 
Old 06-13-2008, 09:57 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

You can use ` characters to use reserved words as column names:

ALTER TABLE theTable DROP `update`
 
Old 06-13-2008, 09:57 AM   #3
bwayson
LQ Newbie
 
Registered: Nov 2006
Location: Ventura California USA
Distribution: openSUSE
Posts: 23

Rep: Reputation: 3
I don't know about MySQL, but in Microsoft SQL and Access, surrounding the column names with square brackets (e.g. select [update], [delete] from myTable) would work.
 
Old 06-13-2008, 10:01 AM   #4
redgoblin
Member
 
Registered: Jun 2005
Location: UK
Distribution: Debian
Posts: 189

Rep: Reputation: 41
Reserved words need to be escaped. In MS SQL it is indeed [word], but in MySQL it's the back tick `word`.

Some documentation for you;

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

The search term you where after is "mysql escape reserved word". But it seems people have beaten me to it.
 
Old 06-13-2008, 12:54 PM   #5
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815

Original Poster
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Thanks Guttorm and redgoblin, the back ticks were the trick.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compare $php variable to indexed distinct mysql columns secretlydead Programming 1 02-18-2008 10:48 PM
MySQL DROP user --- how to fhleung Linux - Software 1 08-15-2007 10:27 AM
delete columns 15 to 27 of a text file powah Programming 1 01-31-2007 02:03 AM
MySQL - UNIQUE values across two columns - non-standard constraint issue benr77 Linux - General 2 11-06-2004 10:48 AM
how do I Add multiple columns mysql in postgres Bheki Linux - Software 1 08-28-2003 02:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration