Python Opearte MS-SQL Use Pymssql, opeartepymssql
See a lot of open source database will use MySQL, Python also use, but I have been used to the use of graphical interface, a strong sense of Operation MS-SQL
Seeing that Python also provides the MS-SQL connection method, you need to use PyMssql.
In the Windows dos cmd command, enter:
pip install pymssl
Pymssql documentation link http://pymssql.org/en/latest/pymssql_examples.html#iterating-through-results
imoort pymssqlconn=pymssql.connect("192.168.6.112","sa","123456","FactoryHome")cursor=conn.cursor()cursor.execute("select * from usera")row=cursor.fetchone()print(row[0])
Connect: Connect to the database address, port and other basic configurations
Cursor: This is a bit like a database Cursor, but I don't know if it will affect a large volume of data.
Fetchone, Fetchall is said to return a List. so it is easy to think of loop to get data
for row in cursor: print ("%s -> %s ",(row[0], row[1]))
Execute is also used to insert Pymssql.
Import pymssqlconn = pymssql. connect ("192.168.6.112", "sa", "", "FactoryHome", "UTF-8" )cursor=conn.cursor()cursor.exe cute ("inset into Table_1 Values (1, 'ddddddd', 'zhang san ') ") conn. commit () conn. close ()
In the insert Chinese operation, it is best to bring the character set of UTF-8, It is not best to be sure to bring, without it will report an error.
Pymssql updates. Currently, execute is also used.
Import pymssqlconn = pymssql. connect ("192.168.6.112", "sa", "", "FactoryHome", "UTF-8" )cursor1_conn.cursor()cursor.exe cute ("Update Table_1 set Name = '王' where id = 3") conn. commit () conn. close ()
The same is true for Pymssql delete operations.
To be continued