python mysqldb 执行这句sql为啥报错
sql="""IFNOTEXISTS(SELECT1FROMinformation_schema.COLUMNS\WHERETABLE_SCHEMA='%s'ANDTAB...
sql = """IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS\
WHERE TABLE_SCHEMA='%s' AND TABLE_NAME='%s' AND\
COLUMN_NAME='%s')THEN ALTER TABLE %s ADD %s VARCHAR(10)\
NOT NULL;END IF;""" % ('dev', 'mytest1', 'aaa', 'mytest1', 'aaa')
cur.execute(sql)
这段代码查dev库中mytest1表中有没有aaa字段,没有就添加,但报1064错误,请问大神python 中应该怎么写 展开
WHERE TABLE_SCHEMA='%s' AND TABLE_NAME='%s' AND\
COLUMN_NAME='%s')THEN ALTER TABLE %s ADD %s VARCHAR(10)\
NOT NULL;END IF;""" % ('dev', 'mytest1', 'aaa', 'mytest1', 'aaa')
cur.execute(sql)
这段代码查dev库中mytest1表中有没有aaa字段,没有就添加,但报1064错误,请问大神python 中应该怎么写 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询