Published by Patrick Mutisya · 14 days ago
Show understanding of how software tools found within a DBMS are used in practice.
DDL commands define the structure of database objects. Typical statements include CREATE, ALTER and DROP.
Example – creating a table for employee records:
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
Name \cdot ARCHAR(50),
Department \cdot ARCHAR(30),
Salary DECIMAL(10,2)
);
DML is used to insert, update, delete and retrieve data. The most common DML statements are INSERT, UPDATE, DELETE and SELECT.
Example – adding a new employee and giving a raise:
INSERT INTO Employee (EmpID, Name, Department, Salary)
VALUES (101, 'Alice Brown', 'Finance', 48000.00);
UPDATE Employee
SET Salary = Salary * 1.05
WHERE EmpID = 101;
SQL combines DML and query capabilities. It allows complex retrieval using WHERE, JOIN, GROUP BY, HA \cdot ING and ORDER BY.
Example – list finance staff earning more than $50,000, ordered by salary descending:
SELECT Name, Salary
FROM Employee
WHERE Department = 'Finance' AND Salary > 50000
ORDER BY Salary DESC;
Transactions ensure a group of operations are treated as a single logical unit. The ACID properties guarantee reliability.
Typical commands:
BEGIN TRANSACTIONCOMMIT – makes changes permanentROLLBACK – undoes all changes in the current transactionExample – transferring $2,000 from one account to another:
BEGIN TRANSACTION;
UPDATE Account
SET Balance = Balance - 2000
WHERE AccNo = 'A123';
UPDATE Account
SET Balance = Balance + 2000
WHERE AccNo = 'B456';
COMMIT;
Indexes speed up data retrieval by providing a fast lookup structure, usually a B‑tree.
Example – creating an index on the Salary column:
CREATE INDEX idx_salary ON Employee (Salary);
Effect: a query such as SELECT * FROM Employee WHERE Salary > 60000 can be satisfied by scanning the index rather than the whole table.
A view is a virtual table defined by a query. It can simplify complex queries, enforce security, and present data in a user‑friendly format.
Example – a view showing only employee names and departments:
CREATE \cdot IEW EmpDept AS
SELECT Name, Department
FROM Employee;
Users with limited privileges can be granted access to EmpDept without seeing salaries.
These are pre‑compiled SQL blocks stored in the DBMS. They encapsulate business logic, reduce network traffic and improve performance.
Example – a procedure that raises salaries for a given department by a percentage:
CREATE PROCEDURE RaiseSalary (
IN dept \cdot ARCHAR(30),
IN pct DECIMAL(4,2)
)
BEGIN
UPDATE Employee
SET Salary = Salary * (1 + pct/100)
WHERE Department = dept;
END;
Triggers automatically execute in response to specific data‑modification events (INSERT, UPDATE, DELETE). They enforce integrity rules or audit changes.
Example – an audit trigger that records every salary change:
CREATE TRIGGER trgsalaryaudit
AFTER UPDATE OF Salary ON Employee
FOR EACH ROW
BEGIN
INSERT INTO SalaryAudit (EmpID, OldSalary, NewSalary, ChangeDate)
VALUES (OLD.EmpID, OLD.Salary, NEW.Salary, CURRENT_TIMESTAMP);
END;
Regular backups protect against data loss. DBMS tools typically offer:
Example command (MySQL syntax) for a logical backup:
mysqldump -u admin -p --single-transaction mydb > mydb_backup.sql
DBMSs manage user authentication and authorisation through roles, privileges and row‑level security.
Example – creating a role for HR staff and granting limited access:
CREATE ROLE hr_role;
GRANT SELECT, INSERT ON Employee TO hr_role;
GRANT EXECUTE ON PROCEDURE RaiseSalary TO hr_role;
Then assign the role to a user:
GRANT hrrole TO aliceuser;
Many DBMSs include built‑in reporting utilities or integrate with external BI platforms. They allow users to generate formatted reports, charts and dashboards directly from query results.
Typical workflow:
Consider a small retail business that needs to maintain product inventory, process sales, and generate monthly sales reports.
| Task | DBMS Tool(s) Used | Typical Commands / Actions |
|---|---|---|
| Create product catalogue | DDL | CREATE TABLE Product (ProdID INT PRIMARY KEY, Name \cdot ARCHAR(100), Price DECIMAL(8,2), Stock INT); |
| Add new stock | DML (INSERT) | INSERT INTO Product \cdot ALUES (2001, 'Wireless Mouse', 25.99, 150); |
| Record a sale | Transaction Management, DML (UPDATE/INSERT) |
|
| Speed up sales queries | Indexing | CREATE INDEX idxsalesdate ON Sales (SaleDate); |
| Restrict employee access | Security & Roles |
|
| Generate monthly sales report | Stored Procedure + Reporting Tool |
|
Before translating to SQL, many designers reason using relational algebra. For example, to find employees in the Finance department earning more than $50,000:
\$\$
\sigma_{Department='Finance' \cdot Salary>50000}(Employee)
\$\$
The equivalent SQL query is shown earlier in the “Query Language” section.
Employee, Department, and Salary tables.
The tools provided by a DBMS—DDL, DML, SQL, transaction control, indexing, views, stored procedures, triggers, backup/recovery, security, and reporting—work together to create robust, efficient, and secure data‑centric applications. Mastery of these tools enables developers to design databases that meet real‑world business requirements while maintaining data integrity and performance.