cnxn = pyodbc.connect(driver="{ODBC Driver 17 for SQL Server}", server="xxx", database="yy", user="abc", password="abc")
cursor = cnxn.cursor()
b = alter table temp1 add column3 varchar(10)
cursor.execute(b)
cursor.fetchall()
from the above code I'm trying to alter the table and add the column as i contain 2 tables 1 is existing table and the other is new table the column from the new table as to be added to the exixting table so i have done the code but i got the error of
ERROR: No results. Previous SQL was not a query.
so please help me out to clear this error.
CodePudding user response:
change the line of code to as below
b = 'alter table temp1 add column3 varchar(10);'
this assigns the entire SQL command as string to the variable b, which then you can use in the call to execute()
function of the cursor.
Also, the ALTER TABLE
SQL statement will not return any results set, so you need not call fetchXX()
method after executing it.