我的代码如下:
import sqlite3 as sql
def execute_sql(sql_command, sql_cursor):
result = sql_cursor.execute(sql_command)
return result
def print_0th_col(sql_result):
for next_record in sql_result:
print(next_record[0])
def create_tables(sql_cursor):
sql_command = '''CREATE TABLE artist
(artist_id INTEGER UNIQUE
artist_name VARCHAR(100),
age INTEGER,
members INTEGER,
formation VARCHAR(4))
'''
execute_sql(sql_command,sql_cursor)
sql_command = '''CREATE TABLE songs
(song_id INTEGER UNIQUE,
song_name VARCHAR(100),
Band_id INTEGER UNIQUE)
'''
execute_sql(sql_command, sql_cursor)
conn = sql.connect('ex9.db')
sql_cursor = conn.cursor()
conn.commit()
conn.close()
def drop_table(sql_cursor,table_name):
sql_command = '''DROP TABLE ''' + table_name
execute_sql(sql_command, sql_cursor)
当我调试它时,它说sqlite3.OperationalError:near" artist_name":语法错误。
任何人都可以告诉我代码有什么问题吗?
答案 0 :(得分:2)
artist_id
行应为:
(artist_id INTEGER UNIQUE,
您的代码最后缺少逗号,
。