How to insert in MSSQL with Python

I used this code that seems to do the trick:

import pyodbc

conn = pyodbc.connect('driver={ODBC Driver 17 for SQL Server};'                                           'server=XXXXXXXXXX;'                                            'database=YYYYYY;'                                            'uid=ZZZZZZ;'                                            'pwd=QQQQQQQQ;')

rs = conn.cursor()


rs.execute('''                INSERT INTO quant_test (symbol,stockprice)                VALUES                ('AAPL',180)                ''')
conn.commit()
rs.execute(''' INSERT INTO quant_test (symbol,stockprice) VALUES ('AAPL',180) ''') conn.commit()

Comments

Popular posts from this blog

Installing Microsoft ODBC Driver to connect to SQL from Python on Mac OS X

Connection to MSSQL with Pythonan and pyodbc (on Mac OS X)

Installing PyCharm on Mac