MySQL create database 1064 (42000) problem

Question:

Hi I have this problem when creating a new database table:

1064 (42000): You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for 
the right syntax to use near '' at line 1

import mysql.connector

db = mysql.connector.connect(
host="localhost",
user="root",
database="ims"
)

mycursor = db.cursor()


mycursor.execute("CREATE TABLE newitem (code VARCHAR(20), price FLOAT(10), color VARCHAR(50), 
nis INT(100), nim INT(100), nil INT(100), nixl INT(100), nixxl INT(100), nif INT(100), nitotal 
VARCHAR(100)")

I’ve also tried few solutions found online but its still not working. Can anyone help with this? Thank you very much!

Asked By: basil

||

Answers:

You need to close your CREATE statement with another )

statement = """CREATE TABLE newitem(
    code VARCHAR(20),
    price FLOAT(10),
    color VARCHAR(50), 
    nis INT(100),
    nim INT(100),
    nil INT(100),
    nixl INT(100),
    nixxl INT(100),
    nif INT(100),
    nitotal VARCHAR(100))""" # two )'s before ending the quote

mycursor.execute(statement)
Answered By: wkl
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.