联合两个表sqlite3

时间:2017-08-01 09:06:34

标签: python sqlite compilation

我是sqlite3的新手,需要你的帮助才能加入这两个表,我需要联合一个coach和team表之间的团队ID,但是在编译时它会告诉我teamID中的teamID存在问题。 知道我的错误在哪里?

def creationTeamDB():
   with sqlite3.connect("teams.db") as db1:
   cursor = db1.cursor()

   cursor.execute('''
   CREATE TABLE IF NOT EXISTS team (
   teamID INTEGER PRIMARY KEY,
   teamName VARCHAR(20) NOT NULL
   )
   ''')

def creationCoachDB():
   with sqlite3.connect("coachs.db") as db2:
   cursor = db2.cursor()

   cursor.execute('''
   CREATE TABLE IF NOT EXISTS coach (
   coachID INTEGER PRIMARY KEY,
   coachName VARCHAR(20) NOT NULL
   teamID INTEGER
   )
   ''')

提前致谢,:) G.B

1 个答案:

答案 0 :(得分:2)

您错过了第二个查询中的逗号

   CREATE TABLE IF NOT EXISTS coach (
   coachID INTEGER PRIMARY KEY,
   coachName VARCHAR(20) NOT NULL,
   teamID INTEGER
   )