Database Connection
Database Connection
Handout
Introduction to Databases (DB) for Beginners
What is a Database?
A database is a collection of data organized to facilitate easy access, management, and
updating. It stores information such as names, addresses, phone numbers, sales records, or
inventory details.
Examples:
1. A customer database for an e-commerce website storing customer names, addresses,
and purchase history.
2. A library database cataloging books, authors, and genres.
3. A hospital database maintaining patient records, treatments, and billing information.
Examples:
1. An online retailer using a database to manage product inventory and customer orders.
2. A university using a database to track student enrollments and grades.
3. A bank using a database to manage account information and transactions.
Types of Databases
The most common type is the Relational Database, where data is stored in tables that can
be related to each other.
Examples:
1. A school database with Students and Classes tables linked by Class ID.
2. A sales database with Orders and Customers tables linked by Customer ID.
3. A project management database with Projects and Tasks tables linked by Project ID.
What is MySQL?
MySQL is a popular Relational Database Management System (RDBMS) used to manage
and interact with relational databases. It is open-source, reliable, and efficient for handling
large data volumes.
Examples:
1. A website using MySQL to store user accounts and login information.
2. A content management system using MySQL to manage articles and comments.
3. An inventory system using MySQL to track stock levels and supplier details.
Examples:
1. A Python script connecting to a MySQL database to fetch user data.
2. A Java application connecting to a MySQL database to update product prices.
3. A PHP web application connecting to a MySQL database to display blog posts.
CRUD Operations
CRUD stands for Create, Read, Update, and Delete—the four basic operations on a
database.
Examples:
1. Create: Adding a new student to the Students table.
SQL Command: INSERT INTO Students (Name, Age, Class, Address)
VALUES ('Rahul', 15, '10th', 'Mumbai');
2. Read: Retrieving all students in the 10th class.
SQL Command: SELECT * FROM Students WHERE Class = '10th';
3. Update: Changing a student's address.
SQL Command: UPDATE Students SET Address = 'Delhi' WHERE StudentID
= 1;
4. Delete: Removing a student from the database.
SQL Command: DELETE FROM Students WHERE StudentID = 1;
Conclusion
A database is a structured system for storing, managing, and retrieving data. MySQL is a
widely-used tool for managing relational databases, enabling CRUD operations on data.
Understanding these basics is crucial for efficiently handling data in various applications.
+-------------------+ +-------------------+
| Students | | Classes |
+-------------------+ +-------------------+
| StudentID | Name | | ClassID | Class |
|-----------|-------| |---------|---------|
| 1 | Rahul | | 101 | 10th |
| 2 | Priya | | 102 | 9th |
+-------------------+ +-------------------+
In this diagram, the Students table and the Classes table are related through the ClassID
field.
Feel free to ask any questions if you need further clarification!