MCS-201 · Unit 16

Data Access Using Python

7 sections

Block 4 · Unit 16Data Access Using Python68 min · 7 sections

Unit 16Data Access Using Python

Follows IGNOU MCS-201, Unit 16

Almost every real application stores its data in a database: student records, bank transactions, orders, bills. This unit first builds the database background you need (what a database and a DBMS are, the entity-relationship and relational models, keys, and the SQL language), and then shows how a Python program connects to a MySQL database, creates tables, inserts, reads, updates and deletes rows, and controls transactions. It ends with CSV files, the simplest way to exchange tabular data, read with Python’s csv module and the pandas library.

In this unit you will learn to

  • Define a database and a DBMS, and list the advantages, limitations and architecture of database systems.
  • Describe the entity-relationship and relational models, and use the terms table, tuple, attribute, primary key, foreign key and candidate key.
  • Write SQL DDL, DML, DCL and TCL statements, using correct MySQL data types.
  • Install and use mysql.connector to connect to MySQL, create databases and tables, and run queries from Python.
  • Insert, update, delete and fetch rows safely with parameterised queries, and manage transactions with commit() and rollback().
  • Read and write CSV files with the csv module, and load and summarise them with pandas.

Sections in this unit

  1. 16.1Databases and Database Management SystemsWhat a database and a DBMS are, who uses a DBMS, the advantages and limitations of databases over files, and the three-tier and three-schema architectures.9 min
  2. 16.2The Entity-Relationship and Relational ModelsModelling data with entities, attributes and relationships, then storing it in tables with tuples, attributes, domains and primary and foreign keys.9 min
  3. 16.3SQL Commands and MySQL Data TypesThe four groups of SQL commands (DDL, DML, DCL, TCL), MySQL data types, and writing CREATE, ALTER, INSERT, SELECT, UPDATE and DELETE statements.10 min
  4. 16.4Connecting Python to MySQLThe Python DB-API, installing MySQL and mysql-connector-python, connecting to the server, using a cursor, and creating and selecting a database.10 min
  5. 16.5Creating Tables and Changing Data from PythonCreating and altering tables from Python, inserting rows safely with parameterised queries, updating and deleting rows, and committing the changes.10 min
  6. 16.6Reading Data and Managing TransactionsFetching results with fetchone, fetchmany and fetchall, buffered cursors and rowcount, and grouping changes into transactions with commit and rollback.9 min
  7. 16.7CSV Files in PythonReading and writing comma-separated files with the csv module, loading them into pandas DataFrames, handling header rows, and computing summary statistics.11 min
↑ ↓ move↵ openTab switch type