1

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.

5
  • 3
    The [ and ] is not valid syntax. It's probably meant to symbolise an optional argument, but you should remove them from your query. Commented Oct 17, 2018 at 7:30
  • 1
    Possible duplicate of MySQL create database if not exist Commented Oct 17, 2018 at 7:31
  • And @johan, Also Thank you. I feel really stupid right now. Commented Oct 17, 2018 at 7:34
  • 1
    Don't worry about it, everyone here have done similar things, it's part of being a developer :) Commented Oct 17, 2018 at 7:35
  • 1
    You may need to read up on typographical and syntax conventions in mysql documentation dev.mysql.com/doc/refman/8.0/en/manual-conventions.html Commented Oct 17, 2018 at 7:45

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I will flag this as the answer in a minute. Thank you!
0

Try below

CREATE TABLE IF NOT EXISTS test (
    test_column date
)  

1 Comment

@ThatOne, that's not required

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.