0% found this document useful (0 votes)
12 views3 pages

Week 4 BIT120 Intro To MySQL

This document outlines a week 4 course on MySQL using phpMyAdmin, covering the creation of databases and tables, data insertion, viewing, filtering, updating, and deleting records. It also includes instructions for adding columns, sorting, limiting results, and using aggregate functions. Each class provides step-by-step SQL commands to perform these operations on a sample 'students' database.

Uploaded by

mcmojustin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Week 4 BIT120 Intro To MySQL

This document outlines a week 4 course on MySQL using phpMyAdmin, covering the creation of databases and tables, data insertion, viewing, filtering, updating, and deleting records. It also includes instructions for adding columns, sorting, limiting results, and using aggregate functions. Each class provides step-by-step SQL commands to perform these operations on a sample 'students' database.

Uploaded by

mcmojustin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Week 4 BIT120 - Introduction to MySQL Using phpMyAdmin

Class 1: Creating a Database

What is a Database?

A database is a collection of related information stored in an organized way.

Steps:

1. Open phpMyAdmin.

2. Click on the SQL tab.

3. Run:

CREATE DATABASE school_db;

4. Click Go.

Class 2: Creating a Table

What is a Table?

A table stores data in rows and columns.

Steps:

1. Select school_db.

2. Click SQL tab.

3. Run:

CREATE TABLE students (

id INT AUTO_INCREMENT PRIMARY KEY,

first_name VARCHAR(50),

last_name VARCHAR(50),

age INT,

grade VARCHAR(5)
);

Class 3: Inserting Data

Inserting means adding new records.

Steps:

INSERT INTO students (first_name, last_name, age, grade)

VALUES

('John', 'Doe', 15, '9A'),

('Jane', 'Smith', 14, '8B'),

('Mary', 'Wambui', 16, '10C');

Class 4: Viewing Records

Use SELECT to view data.

Steps:

SELECT * FROM students;

Class 5: Filtering Data

Use WHERE to filter records.

Steps:

SELECT * FROM students WHERE grade = '9A';

Class 6: Updating Records

Use UPDATE to change data.

Steps:

UPDATE students SET age = 17


WHERE first_name = 'Mary' AND last_name = 'Wambui';

Class 7: Deleting Records

Use DELETE to remove data.

Steps:

DELETE FROM students WHERE id = 1;

Class 8: Adding a Column

Use ALTER TABLE to change structure.

Steps:

ALTER TABLE students ADD email VARCHAR(100);

Class 9: Sorting and Limiting

ORDER BY arranges output, LIMIT restricts count.

Steps:

SELECT * FROM students ORDER BY age DESC LIMIT 2;

Class 10: Aggregate Functions

Perform calculations on data.

Steps:

SELECT COUNT(*) AS total_students FROM students;

SELECT AVG(age) AS average_age FROM students;

You might also like