Introduction to Database
Learning Objective: Explain database concepts and their business applications
When you check your bank balance at Nabil Bank, the system instantly retrieves your account details from millions of records. When Daraz shows you products matching your search, it queries a massive database. When Nepal Telecom generates your phone bill, it processes your call records stored in a database. Databases are the backbone of modern business information systems.
What Is a Database?
A database is an organized collection of related data stored electronically, designed for easy access, management, and updating. Unlike a simple spreadsheet, a database can handle large volumes of data, support multiple users simultaneously, and enforce data integrity rules.
Database vs. Spreadsheet:
| Feature | Spreadsheet | Database | |---------|------------|----------| | Best for | Small datasets, quick calculations | Large datasets, complex relationships | | Users | Usually one at a time | Multiple users simultaneously | | Data volume | Thousands of rows | Millions of records | | Relationships | Limited | Tables linked through relationships | | Example | Excel, Google Sheets | MySQL, Oracle, MS Access |
Key Database Concepts
Tables
A database stores data in tables (also called relations). Each table has:
- Rows (Records): Each row represents one entry (e.g., one customer)
- Columns (Fields): Each column represents an attribute (e.g., name, phone, address)
Example: Customer Table for a Kathmandu Store
| CustomerID | Name | Phone | Address | Balance (Rs.) | |-----------|------|-------|---------|--------------| | C001 | Ram Sharma | 9841000001 | Kathmandu | 15,000 | | C002 | Sita Thapa | 9851000002 | Lalitpur | 8,500 | | C003 | Hari Gurung | 9861000003 | Pokhara | 22,000 |
Primary Key
A primary key is a unique identifier for each record. In the table above, CustomerID is the primary key -- no two customers can have the same ID.
Foreign Key
A foreign key links one table to another. For example, an Orders table might have a CustomerID column that references the Customer table, connecting each order to its customer.
Queries: Asking Questions to the Database
A query retrieves specific information from the database. Queries use a language called SQL (Structured Query Language).
Common Query Examples:
- "Show all customers from Kathmandu"
- "Find customers with balance greater than Rs. 10,000"
- "Count the total number of orders placed last month"
- "Calculate total sales for each product category"
SQL Example: To find customers from Kathmandu:
SELECT Name, Phone FROM Customers WHERE Address = 'Kathmandu';
This would return: Ram Sharma, 9841000001
Database Management Systems (DBMS)
A DBMS is software that manages databases. It provides tools to create, store, retrieve, and secure data.
Popular DBMS:
- Microsoft Access: Simple desktop database, good for small businesses
- MySQL: Free, open-source, used by many websites and applications
- Oracle: Enterprise-level, used by large organizations (banks, telecom companies)
- SQLite: Lightweight, used in mobile apps
Business Applications of Databases
| Business Area | Database Use | |--------------|-------------| | Banking | Customer accounts, transactions, loan records (NIC Asia, Nabil Bank) | | E-commerce | Product catalogs, orders, customer profiles (Daraz) | | Telecom | Call records, billing, subscriber data (Ncell, NTC) | | Healthcare | Patient records, appointment scheduling, medicine inventory | | Education | Student records, grades, attendance (university systems) | | Government | Citizen records, tax data, land registry (Nepal's Nagarik App) |
Data Security and Integrity
Databases include features to protect data:
- User authentication: Only authorized users can access the database
- Backup and recovery: Regular backups protect against data loss
- Data validation: Rules ensure only valid data is entered
- Encryption: Sensitive data (bank details, passwords) is encrypted
Key Term: A Database Management System (DBMS) is software that allows users to create, manage, and query databases efficiently while ensuring data security and integrity.
Summary
- A database is an organized collection of data stored in tables with rows and columns.
- Primary keys uniquely identify each record; foreign keys link related tables.
- Queries (often written in SQL) retrieve specific data from the database.
- Databases are essential for banking, e-commerce, telecom, and government services in Nepal.
Quick Quiz
1. What is a primary key in a database table?
2. Which of the following is a Database Management System (DBMS)?
3. A query in a database is used to: