1 of 39

དཔལ་ལྡན་འབྲུག་གཞུང་། ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།

Department of School Education

Ministry of Education & Skills Development

Online Training for ICT Teachers

17 February 2023

Classes XI & XII ICT Curriculum

SQLite SESSION I

2 of 39

SESSION I

3 of 39

Session Outline

ICT Curriculum

Introduction to Database

Comparing Spreadsheet and Database

Creating Database using SQLite

Stock Register Database

1

Student Details Database

SQLite

2

3

4

5

6

4 of 39

ICT Curriculum

5 of 39

Competency

Objectives

Use a database management system in an application for easy access, and secure data storage and management.

Develop a CRUD application using Tkinter as frontend, Python as backend and SQLite for the database

Insert, delete, update, and Select data from the SQLite database using SQL.

Develop a database application using the SQLite module.

Create a SQLite database.

Explain the functions of the database system.

6 of 39

Content Scope

Database Management System

Database Application

Definition of Database

Importance of Database

Terminology in Database

CRUD Operations

Database

Tuples

Attributes

Tables

Create

Read

Update

Delete

Create table

Read Record

Update Record

Delete Record

Drop Table

Select Record

Insert Record

Import sqlite3 library

connect()

execute()

commit()

Close()

SQLite Browser

SQLite Database

SQLite Query

Connect to Database

SQLite Database with Tkinter

7 of 39

Career Opportunities

Data Administrator

Data Analyst

Business Intelligence Analyst

Database Developer

Data Scientist

Software Developer

Cloud Database Engineer

8 of 39

Introduction to Database

9 of 39

A database is an organized collection of data, which is stored on a computer system.

1

It is used to store, manage, and manipulate data in a structured format.

2

They are an essential part of any organization’s IT infrastructure.

3

Uses SQL(Structured Query Language) for managing and manipulating databases.

4

Examples of Database Management System (DBMS): MySQL, MongoDB, SQLite, MS-Access, Oracle

5

Database

10 of 39

Features

Data Reliability

1

Data Security

2

Data Integrity

3

Data Manipulation

4

Collaboration among users

5

Data Redundancy

6

11 of 39

SQLite

It is an embedded SQL database engine and it is not a standalone application, but rather a library that software developers embed in their applications.

3

It is a self-contained, serverless, zero-configuration, and transactional SQL database engine.

2

Software library that provides a database management system.

1

12 of 39

Comparing Spreadsheet and Database

13 of 39

Database and Spreadsheet

Spreadsheet

SQLite

Discuss how are these two similar?

14 of 39

Store large amounts of data

1

Search and retrieve specific data

2

Sort and filter data

3

Perform calculations and analysis on data

4

Use tables to organize data.

5

Similarities

15 of 39

Differences

Database

Spreadsheet

  1. store, organize, and retrieve large amounts of data.
  2. used for complex data management and organization. (Trillion rows of data)
  3. Uses specific query languages like SQL to interact with the data in a database
  4. Designed for use by teams or organizations
  5. used for tasks such as storing customer information and managing online stores.
  1. organize, store, and manipulate data in a tabular format
  2. used for simple data manipulation and analysis (Million rows of data)
  3. Relies on simple formulas and functions
  4. Designed for use by individuals
  5. used for tasks such as financial analysis and budgeting

16 of 39

Creating Database using SQLite

17 of 39

First database in SQLite

Output

Sample Code

Variable_name = sqlite3.connect(‘DatabaseFileName.db’)

Import the sqlite3 module

18 of 39

Stock Register Database

19 of 39

Stock Register Database

Write a python program to create a table named Stocks in the StockRegister.db with the following fields:

  • StockNo
  • StockName
  • Quantity
  • PricePerItem

Add 4 records in the table Stocks and view all the records from the table.

20 of 39

Sample Code

Output

21 of 39

Stock Register Database

Write a python program to create a table named Stocks in the StockRegister.db with the following fields:

  • StockNo
  • StockName
  • Quantity
  • PricePerItem

22 of 39

Sample Code

Output

23 of 39

Stock Register Database

Write a python program that connects to the StockRegister.db and add 4 records in the table Stocks(Add few duplicate data).

24 of 39

Sample Code

Output

25 of 39

Stock Register Database

Write a python program that connects to the StockRegister.db database and to view all the records in the Stocks table.

26 of 39

Sample Code

Output

27 of 39

Stock Register Database

Write a python program and connect to StockRegister.db.

Retrieve and view the records where StockNo=102

28 of 39

Sample Code

Output

29 of 39

A primary key is a special type of column in a table that is used to uniquely identify each row in the table.

1

Special identifier for each record in the table.

2

Think of a primary key as a special type of ID number, like a CID No or a passport number.

3

Primary keys are used to maintain the integrity of the data in a table, by ensuring that each row has a unique identifier.

4

Primary key values must be unique and can't be null.

5

Primary Key

30 of 39

Identify the Primary Key

CustID

Name

Bill Amount

Remarks

001

Sonam

12000

Paid

002

Tshering

23000

Not paid

003

Sonam

23000

Not Paid

31 of 39

Student Details Database

32 of 39

Student Details Database

Write a python program to create a new database StudentDetails.db and create a table named Details with the following fields:

  1. StdCode
  2. StdName
  3. Class
  4. Age
  5. Gender

Set StdCode as the Primary Key.

Add four records and the view the records

33 of 39

Sample Code

Output

34 of 39

Student Details Database

Write a python program to connect to the database StudentDetails.db

  • Update the name of the student as “Karma Lhamo” where StdCode=1002

35 of 39

Sample Code

Output

36 of 39

Student Details Database

Write a python program to connect to the database StudentDetails.db

  • Delete the record where StdCode=1003
  • Drop the table

37 of 39

Sample Code

Output

38 of 39

Post Session Activity

Complete the tasks Activity I and Activity II under SQLite topic in the Google Classroom.

39 of 39