Python3.7.1 learning (eight) Python to access SQL Server database

  A, pip install pymssql to install pymssql library

          

       Two, Python SQL Server database connection

               Example code:                

# - * - Coding: UTF-. 8 - * - 
"" "
@author: Administrator
" ""
Import pymssql


DEF main ():
# Create SqlServer connection
conn = pymssql.connect (host = 'server IP', user = 'sa ', password =' **** ', database =' FamilyDoctor ')

# interact with the database, if the machine, only the edit link string
# conn = host pymssql.connect (=' . ', database =' FamilyDoctor ')
# create a cursor
CUR = conn.cursor ()
cur.execute ( 'the SELECT Top 5 * the FROM [dbo]. [Resident]')
# If the update / delete / insert remember to conn.commit ()
# database transaction otherwise unable to submit
print (cur.fetchall ())
# close the cursor
cur.close ()
# close the connection
conn.Close ()

IF __name__ __ == '__main__':
main()

       

 

 

转载于:https://www.cnblogs.com/simpleBlue3/p/10728421.html

Guess you like

Origin blog.csdn.net/weixin_33845477/article/details/93307541