Python connects SQL Server database MSSQL

Source: Internet
Author: User
Tags mssql

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.