Python wants to interact with the MSSQL database by first downloading the package named "Pymssql" and then import the package.
Address: Https://pypi.python.org/pypi/pymssql/2.1.0#downloads
Baidu Cloud (3.4win32+64): http://pan.baidu.com/s/1eSyPO5c
After download, the system automatically selects the folder where Python is located and installs it in the Python\lis\site-packages folder.
Then, in Python's idle, typed in, import pymssql.
If there is no error, then congratulations on your installation success.
After the installation is successful, we use the following statement to interact with the MSSQL database.
1 Importpymssql2 3Conn=pymssql.connect (host='192.168.0.184', user='SA', password='pwd', database='shcemdw')4 " "5 If you interact with the native database, simply modify the link string6 conn=pymssql.connect (host= '. ', database= ' Michael ')7 " "8Cur=conn.cursor ()9 TenCur.execute ('Select Top 5 * FROM [dbo]. [Dim_area]') One #if Update/delete/insert remember to Conn.commit () A #Otherwise, the database transaction cannot be committed - Print(Cur.fetchall ()) - the cur.close () - -Conn.close ()
As above, we have completed the interaction between Python and the database.
Python connects SQL Server database MSSQL