Can't create an SQL Table in Python using input as name
<p>I have a little issue with my python code. I want to take the input from user and based on that create an SQL table with that name. I take the input in table_name variable and want to do it so:</p>

<pre><code>sql = "CREATE TABLE %s" % table_name
cur.execute(sql)
</code></pre>

<p>Let's say I run it with input "books". I get this error:</p>

<blockquote>
  <p>File "XXX", line 55, in FUNCTIONNAME<br> cur.execute(sql)<br>
  sqlite3.OperationalError: near "books": syntax error</p>
</blockquote>

<p>Any ideas on what is wrong? I googled it and above code should be OK, but it isn't...</p>

<p>That's most probably cause you are not passing the table definition (column names and their type , size). What I see from posted code is that you are passing only table name and so your query becomes below which is totally wrong</p>

<pre><code>CREATE TABLE books
</code></pre>

python sql sqlite