简体   繁体   中英

SQL Alchemy python DELETE records, strange schema

I have problem with clearing the table (deleting records).

The table have rep schema like that: PROD\\USER.TableName

My code looks like that:

params = urllib.parse.quote_plus("DRIVER={SQL 
SERVER};SERVER=XXXXX;DATABASE=DBNAME;")
engine = sqlalchemy.create_engine("mssql+pyodbc:///?odbc_connect=%s" % 
params)

c=engine.connect()
sql=("DELETE * FROM PROD\\USER.TableName")
result=c.execute(sql)

What am I doing wrong and how can I makes this work (I cannot change the schema of DB).

ERROR: Incorrect syntax near *

delete doesn't take a column list (unless you're using top ). Just lose the * . Additionally, it's probably a good idea to escape the schema name:

sql=("DELETE FROM [PROD\\USER].TableName")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM