That One
That One

Reputation: 597

MySQL Create table IF NOT EXISTS syntax error

I am kind of new to MySQL and i am trying to get to know the commands, and i thought starting with how to make a table might not be such a bad idear.

However, the only command i find online keeps returning a syntax error. I must be doing something wrong, do you guys see what it is?

CREATE TABLE [IF NOT EXISTS] test (test_column date);

-Natan

EDIT 1:

If you downvote, please leave a reason why and be prepared to remove it if i fix it.

EDIT 2:

Stackoverflow had this question identified as a duplicate of a completely different question. so i am now required to explain why. Hereby: My question is about the create table statement, this persons code is much more complicated and about the IF statement.

Upvotes: 1

Views: 3151

Answers (2)

Fahmi
Fahmi

Reputation: 37473

Try below

CREATE TABLE IF NOT EXISTS test (
    test_column date
)  

Upvotes: 0

cn0047
cn0047

Reputation: 17071

Your query must looks like this:

CREATE TABLE IF NOT EXISTS test (test_column date);

[IF NOT EXISTS] it's part which you can omit, it isn't required (that's why it is in brackets). And it means that you can run query without this part, like:

CREATE TABLE test (test_column date);

But in this case your query will fail if table test already exists.

Upvotes: 3

Related Questions