0% found this document useful (0 votes)
7 views5 pages

Database Software Basics

The document provides an overview of database software basics, including definitions of databases, tables, primary keys, and SQL commands. It explains the structure of relational databases and demonstrates SQL commands for creating, inserting, querying, updating, and deleting data. Additionally, it covers aggregate functions and the process of dropping a table.

Uploaded by

popcyavan256
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)
7 views5 pages

Database Software Basics

The document provides an overview of database software basics, including definitions of databases, tables, primary keys, and SQL commands. It explains the structure of relational databases and demonstrates SQL commands for creating, inserting, querying, updating, and deleting data. Additionally, it covers aggregate functions and the process of dropping a table.

Uploaded by

popcyavan256
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
You are on page 1/ 5

Lecturer: Zishan Ahmed Introduction to Computers (Final-term Notes)

Topic: Database Software Basics


1. Database

A database is an organized collection of data that is stored and managed to make it easy to access, update,
and manipulate. It is designed to efficiently handle large amounts of information and is typically managed
by a Database Management System (DBMS).

Examples of Databases: A library catalog, employee records, banking systems, and online retail websites.

2. Table

A table is the fundamental structure in a relational database. It consists of:

• Records (Rows): Each row represents a single data entity or instance (e.g., a single customer in a
customer database).
• Fields (Columns): Each column represents a specific attribute of the data (e.g., a customer’s name or
phone number).

3. Primary Key

A primary key is a column (or set of columns) in a table that uniquely identifies each row. It ensures that
no duplicate values exist for this column.

Purpose: To establish the unique identity of a record (e.g., a unique ID for a student).

5. SQL (Structured Query Language)

SQL is the standard language used to interact with relational databases. SQL commands are categorized
based on their functionality. Here are two primary types:

i) Data Definition Language (DDL)

DDL commands define or modify the structure of database objects like tables, indexes, and schemas. These
commands affect the schema and are not used to manipulate data directly.

ii) Data Manipulation Language (DML)

DML commands deal with the manipulation of data stored in database tables. These commands allow you
to retrieve, insert, update, or delete data.

1
Lecturer: Zishan Ahmed Introduction to Computers (Final-term Notes)

SQL TYPE EXAMPLE

DDL CREATE, DROP, TRUNCATE

DML SELECT, INSERT, UPDATE, DELETE

Some SQL queries with examples:

1. Creating a Table

CREATE TABLE Students (

StudentID INT PRIMARY KEY,

Name VARCHAR(50),

Age INT,

Department VARCHAR(20),

GPA FLOAT,

ScholarshipAmount FLOAT

);

2. Inserting Data

INSERT INTO Students (StudentID, Name, Age, Department, GPA, ScholarshipAmount)

VALUES

(1, 'Alice', 20, 'Computer Science', 3.8, 1500.0),

(2, 'Bob', 22, 'Mathematics', 3.5, 1000.0),

(3, 'Charlie', 21, 'Physics', 3.7, 1200.0),

(4, 'Daisy', 23, 'Biology', 3.4, 800.0),

(5, 'Eve', 20, 'Chemistry', 3.9, 2000.0),

(6, 'Frank', 24, 'Engineering', 3.6, 1100.0);

3. Querying Data

a) Select all data

SELECT * FROM Students;

2
Lecturer: Zishan Ahmed Introduction to Computers (Final-term Notes)

StudentID Name Age Department GPA ScholarshipAmount


1 Alice 20 Computer 3.8 1500
Science
2 Bob 22 Mathematics 3.5 1000
3 Charlie 21 Physics 3.7 1200
4 Daisy 23 Biology 3.4 800
5 Eve 20 Chemistry 3.9 2000
6 Frank 24 Engineering 3.6 1100

b) Select only StudentID, Name and GPA

SELECT StudentID, Name, GPA FROM Students;

StudentID Name GPA


1 Alice 3.8
2 Bob 3.5
3 Charlie 3.7
4 Daisy 3.4
5 Eve 3.9
6 Frank 3.6

c) Select only Name and GPA for Students with GPA > 3.6

SELECT Name, GPA FROM Students WHERE GPA > 3.6;

Name GPA
Alice 3.8
Charlie 3.7
Eve 3.9
Frank 3.6

d) Sort the data in Ascending (low to high) order of GPA

SELECT Name, GPA FROM Students ORDER BY GPA ASC;

Name GPA
Daisy 3.4
Bob 3.5
Frank 3.6
Charlie 3.7
Alice 3.8
Eve 3.9

e) Sort the data in Descending (high to low) order of GPA

SELECT Name, GPA FROM Students ORDER BY GPA DESC;

Name GPA
Eve 3.9
Alice 3.8
Charlie 3.7

3
Lecturer: Zishan Ahmed Introduction to Computers (Final-term Notes)

Frank 3.6
Bob 3.5
Daisy 3.4

f) Select all the fields for the student with the name ‘Daisy’

SELECT * FROM Students WHERE Name = ‘Daisy’;

StudentID Name Age Department GPA ScholarshipAmount


4 Daisy 23 Biology 3.4 800

Aggregate Functions

a) Show the Maximum Scholarship Amount:

SELECT MAX(ScholarshipAmount) FROM Students;

MAX(ScholarshipAmount)
2000.0

b) Show the Minimum Scholarship Amount:

SELECT MIN(ScholarshipAmount) FROM Students;

MIN(ScholarshipAmount)
800.0

c) Show the Average Scholarship Amount:

SELECT AVG(ScholarshipAmount) FROM Students;

AVG(ScholarshipAmount)
1266.67

d) Show the total Scholarship Amount:

SELECT SUM(ScholarshipAmount) FROM Students;

SUM(ScholarshipAmount)
7600.0

4. Updating Data

a) Update the GPA of student with ID 1 to 4.00.

UPDATE Students

SET GPA = 4.0

WHERE StudentID = 1;

4
Lecturer: Zishan Ahmed Introduction to Computers (Final-term Notes)

StudentID Name Age Department GPA ScholarshipAmount


Computer
1 Alice 20 4.0 1500
Science

5. Inserting New Rows

INSERT INTO Students

(StudentID, Name, Age, Department, GPA, ScholarshipAmount)

VALUES

(7, 'Grace', 19, 'Physics', 3.3, 700.0),

(8, 'Helen', 22, 'Mathematics', 3.6, 1100.0);

StudentID Name Age Department GPA ScholarshipAmount


1 Alice 20 Computer 4.0 1500
Science
2 Bob 22 Mathematics 3.5 1000
3 Charlie 21 Physics 3.7 1200
4 Daisy 23 Biology 3.4 800
5 Eve 20 Chemistry 3.9 2000
6 Frank 24 Engineering 3.6 1100
7 Grace 19 Physics 3.3 700
8 Helen 22 Mathematics 3.6 1100

6. Deleting Data

a) Delete the row of student with ID 4.

DELETE FROM Students WHERE StudentID = 4;

StudentID Name Age Department GPA ScholarshipAmount


1 Alice 20 Computer 4.0 1500
Science
2 Bob 22 Mathematics 3.5 1000
3 Charlie 21 Physics 3.7 1200
4 Daisy 23 Biology 3.4 800
5 Eve 20 Chemistry 3.9 2000
6 Frank 24 Engineering 3.6 1100
7 Grace 19 Physics 3.3 700
8 Helen 22 Mathematics 3.6 1100

7. Dropping/Completely removing the Table

DROP TABLE Students;

To Practice Online, Go to This Link: https://sqliteonline.com/

You might also like