Syntax error which won't let me create a table in my database

0

So I have the following code:

String SQLString = $"CREATE TABLE IF NOT EXISTS `accounts` (" +
                                $"`SQLID` INT(11) NOT NULL AUTO_INCREMENT," +
                                $"`socialClub` VARCHAR(64) NOT NULL DEFAULT \"\"," +
                                $"`userName` VARCHAR(64) NOT NULL DEFAULT \"\"," +
                                $"`Cash` INT(11) NOT NULL DEFAULT `0`," +
                                $"`Level` INT(11) NOT NULL DEFAULT `1`," +
                                $"`Age` INT(11) NOT NULL DEFAULT `0`," +
                                $"`Health` INT(6) NOT NULL DEFAULT `1`," +
                                $"PRIMARY KEY (`SQLID`));";

And I get the following error when I turn on my server:

        MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '`0`,`Level` INT(11) NOT NULL DEFAULT `1`,`Age` INT(11) NOT NULL DEFAULT `0`,`Hea' at line 1
       at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
       at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
       at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
       at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
       at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
       at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
       at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
       at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
mysql
asked on Stack Overflow Mar 15, 2020 by Andrei Radu • edited Mar 15, 2020 by Rob Moll

1 Answer

1

You are incorrectly escaping the DEFAULT clause. Just remove the backticks and your query is syntactically correct.

answered on Stack Overflow Mar 15, 2020 by Yennefer

User contributions licensed under CC BY-SA 3.0