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.

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

2 Answers2

2

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.

cn007b
  • 16,596
  • 7
  • 59
  • 74
0

Try below

CREATE TABLE IF NOT EXISTS test (
    test_column date
)  
Fahmi
  • 37,315
  • 5
  • 22
  • 31