I'm new to connecting sql server using python.I need to read some data from sql server do the processing & upload the processed data on sql server.All of these task will be done using python. So I have written the code to pull the data from sql server,did the processing & finally while I'm trying to upload the data on sql server then my code is working fine I'm not getting any error message from python.But I'm unable to see the table on SQL Server, even if I'm trying to retrieve the data from sql server using my python code, I'm getting error message
pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'output1'. (208) (SQLExecDirectW)")
Below is the code I used to insert data onto sql server
conn = sqlite3.connect('Driver={SQL Server};'
'Server=My server name;'
'Database=my data base name;'
'uid=my uid;pwd=my password')
c=conn.cursor()
date = dt.datetime.today().strftime("%m/%d/%Y")
dataToUpload['OPT_TYPE']=opt_type
dataToUpload['Date']=date
list_opt_output=dataToUpload.values.tolist()
c.execute('''CREATE TABLE if not exists output1
(Class text,Location text,Name text,Maths decimal(5,2), nonMaths decimal(5,2), promopercent decimal(5,3),OPT_TYPE text,Date date)''')
conn.commit()
print("Output table created")
c.executemany('''INSERT INTO output1(Class,Location,Name,Maths, nonMaths,promopercent,OPT_TYPE,Date) VALUES (?,?,?,?,?,?,?,?)''', list_opt_output)
conn.commit()
conn.close()
Can you guide me to resolve this issue?
sqlite3and the syntaxCREATE TABLE IF NOT EXISTSis invalid. There'sDROP TABLE IF EXISTSandCREATE OR ALTERonly for programmability objexts like stored procedures, views, triggers and functionsCREATE TABLE IF NOT EXIST. After this statement I put a print statement "Table Created" & I was getting this message. Also I didn't have any try catch block. Any way after reading your comment I removed theCREATE TABLE IF NOT EXISTS& using onlyCreate table. I'm running my code. I will let you know once it done