简体   繁体   中英

pymssql sql update statement

I have the below syntax. The first cursor.execute \\ fetchone pulls back the one row that I want to update. But when I try to run the update query, it updates multiple records.

cursor.execute("Select * FROM [DisneyConvoIndex] where [ConversationBaseIndex]=%s order by length DESC;", '0101CFE27C560BEB6C1073FBF741997D79EDBD4610AC')

row = cursor.fetchone()

for row in row:
    cursor.execute("UPDATE [DisneyConvoIndex] set [toreview] = 'yes'")

You're trying to update the row after it's returned. You're just dealing with the data at that point, not the object in the DB. You need to limit the rows you're updating with a where clause. So, use something like

cursor.execute( "UPDATE [DisneyConvoIndex] set [toreview] = 'yes' WHERE [ConversationBaseIndex]=%s", '0101CFE27C560BEB6C1073FBF741997D79EDBD4610AC' )

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