Interaction Python & SQL Server
SQL Server est le système de gestion de bases de données relationnelles de Microsoft. Nous verrons connecter se connecter à une base de donnée SQL Server et effectuer les opérations CRUD.
Prerequisites
- SQL Server
- ODBC Driver for SQL Server
- Pyodbc
1. Install SQL Server
-
Téléchargemnt
-
Installation
-
Démarrage
2. Install ODBC Driver for SQL Server
-
Téléchargemnt
-
Installation
-
Démarrage
3. Install Pyodbc
4. Create a database
Create a new database called algojungle.
Packages
Paths & Config
Connection to database
Interaction with database
0. Create a table
1. CREATE : Insert data
sql3 = """
INSERT INTO customers (DepartmentID, Name, GroupName)
VALUES (1, 'Engineering', 'Research and Development'),
(2, 'Tool Design', 'Research and Development'),
(3, 'Sales', 'Sales and Marketing'),
(4, 'Marketing', 'Sales and Marketing'),
(5, 'Purchasing', 'Inventory Management'),
(6, 'Research and Development', 'Research and Development'),
(7, 'Production', 'Manufacturing'),
(8, 'Production Control', 'Manufacturing'),
(9, 'Human Resources', 'Executive General and Administration'),
(10, 'Finance', 'Executive General and Administration'),
(11, 'Information Services', 'Executive General and Administration'),
(12, 'Document Control', 'Quality Assurance'),
(13, 'Quality Assurance', 'Quality Assurance'),
(14, 'Facilities and Maintenance', 'Executive General and Administration'),
(15, 'Shipping and Receiving', 'Inventory Management'),
(16, 'Executive', 'Executive General and Administration');
"""
conn.execute(sql3)
conn.commit()
2. READ : Read data
3. UPDATE : Update table
4. DELETE : Delete data
Close connection
References
- SQL Server: https://www.postgresql.org/download/
- Pyodbc: https://www.psycopg.org/docs/install.html