F
F
FrOms2021-05-01 08:30:22
Python
FrOms, 2021-05-01 08:30:22

How to insert data into pypyodbc SQL table?

I have a table like this:
608ce65550213443950423.png
And this is the code:

appr = int(input('Введите оценку: '))

mySQLQuery = (f'''
                    SELECT {subject}
                    FROM dbo.rating

                    insert into dbo.rating ({subject}) values ('{appr}')
                                    ''')
cursor.executemany(mySQLQuery)

After its execution, a new row appears in the table, where "id"=NULL, and I need it to add a rating to the existing row. If I remove the "id" column, then everything will work fine, but I need it to delete or change data in the table. Tell me how to solve this problem?!
PS variables "subject"-subject, "appr"-evaluation

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yupiter7575, 2021-05-01
@yupiter7575

Some kind of request you have is strange ... have you tried it separately? Add an id characteristic to auto_increment and see what happens

O
o5a, 2021-05-01
@o5a

added a grade to an existing line

in SQL is called UPDATE
mySQLQuery = (f'''update dbo.rating set `{subject}` = {appr} where id = '{your_id}')''')

better by passing parameters
mySQLQuery = f'''update dbo.rating set `{subject}` = %s where id = %s'''
cursor.execute(mySQLQuery, (appr, your_id))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question