0

I'm testing some simple scripts to get the feel of MySQL in Workbench. I've created a database called 'myschema' and am trying to execute the following script in the scripting shell

ALTER TABLE 'myschema'.'employee' DROP COLUMN 'date_of_birth' ;

However, I always get the following error:

Uncaught exception while executing C:\Users\Owner\AppData\Roaming\MySQL\Workbench\scripts\deletion.py: File "c:\users\owner\appdata\roaming\mysql\workbench\scripts\deletion.py", line 9

ALTER TABLE 'myschema'.'employee' DROP COLUMN 'date_of_birth' ;

SyntaxError: invalid syntax

This is a very basic command, so I'm confused as to why it's not working. I've tried getting rid of the quotes and the 'myschema' part, but I keep getting the same error. What am I doing wrong?

In fact, I've found that no SQL queries at all work in the scripting shell. They all return syntax errors

SOLVED: I was using the wrong editor. Was solved by using the SQL Query Editor instead of the Scripting Shell

2
  • If you are in the database 'myschema' don't use myschema.employee,just use employee.Don't use quotes.Just give it as it is Commented May 7, 2017 at 20:18
  • As I said in my post, I've tried both of those changes and get the same error Commented May 7, 2017 at 20:24

2 Answers 2

1

Simply use:

ALTER TABLE myschema.employee DROP COLUMN date_of_birth;

or if you had non standard identifiers or reserved keywords to escape, you could use backticks:

ALTER TABLE `myschema`.`employee` DROP COLUMN `date_of_birth`;
Sign up to request clarification or add additional context in comments.

9 Comments

The only reason you "must" escape is a conflict with a reserved keyword and even then it's often contextual.
Like I said in my post, I've tried that (getting rid of the quotes). Still getting the same error.
@Bob can you post the describe for the employee table here?
@tadman - Agreed. I just mentioned it here for reference. Nothing more. :)
Yep! Just trying to add a bit more context. I see people escape all sorts of things out of unfounded paranoia, it borders on superstition, so a rational explanation helps defray that.
|
1

Remember than you should to use back quote for identifiers:

ALTER TABLE `myschema`.`employee` DROP COLUMN `date_of_birth` ;

3 Comments

I just made that change, but I'm still getting the same error
MySQL is not Postgres. MySQL is not even normal when it comes to escaping identifiers.
Much better! Yeah, some days it's easy to cross the streams.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.