Relational databases store data in tables that are connected through primary and foreign keys. This allows data from different tables to be related, providing meaningful insights. Relational database objects include tables, primary keys, foreign keys, indexes, and sequences. SQL uses DDL commands like CREATE, ALTER, and DROP to define database structures and DML commands like INSERT, UPDATE, DELETE, and SELECT to manipulate data.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
13 views9 pages
Uploaded Documents
Relational databases store data in tables that are connected through primary and foreign keys. This allows data from different tables to be related, providing meaningful insights. Relational database objects include tables, primary keys, foreign keys, indexes, and sequences. SQL uses DDL commands like CREATE, ALTER, and DROP to define database structures and DML commands like INSERT, UPDATE, DELETE, and SELECT to manipulate data.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9
Database Design and Development
22/03939 Purity Wamaitha
Explore the Role in the relational database by showing how it works Relational database Brief overview A relational database stores data in tables, where each table represents a category of information. These tables are connected by unique IDs or keys that is primary keys, and foreign keys. Each row in a table corresponds to a record and the column represents data attributes. Keys allow users to unlock related data entries across tables. Role of Relational Database -Data Relationships: Relational databases connect data from different tables, creating useful information. -Meaningful Insights: Organizations decipher the relationship between data sets, leading to valuable. insights. Relational database management system objects include -Tables - fundamental building blocks in RDBMS where data is stored in tables, consisting of columns and rows. Each row is a record and each table has a primary key. -Primary key – a unique identifier for each row in a table. Ensures data integrity and facilitates efficient data retrieval. Helps establish relationships between tables. -A foreign key - a field in one table that refers to a primary key in another table. Useful for simplifying complex queries or providing specific data subsets. -Indexes -data structures that contain a copy of one or more columns from a database table. Improve query performance. -Indexes -Improve query performance by providing direct access to rows in a table. They reduce the need for full table scans. -Sequences -Generates unique integers that can be shared by multiple users. - Synonyms are an alternative name for objects. It simplifies access and provides abstraction. (a) Using SQL (Data Definition Language (DDL)) to define RDBMS Objects like tables. DDL commands focus on defining and managing the database schema, ensuring data integrity and efficient storage. DDL provides essential operations for managing the structure of a database. 1. CREATE: It is used to add new objects to the database. Use CREATE TABLE to define a new table with specified columns and data types. Apart from tables, you can create other database objects such as views, indexes, triggers, stored procedures Example in a SQL statement CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, Full Name VARCHAR(50), Occupation VARCHAR(50), Age Int, Monthly Salary DECIMAL) ; 2. ALTER: The alter command modifies the structure of an existing tables
You can use it to:
Add columns- Extend the schema by adding new columns
Modify columns: Change data types, constraints, or default values.
Drop columns: Remove unnecessary columns.
Rename tables: Alter the name of an existing table.
Add constraints: Set up primary keys, foreign keys, or unique constraints.
Use ALTER TABLE To modify an existing table (for example; adding or
dropping columns)
Example using SQL statements
-Adding a new column:
ALTER TABLE Employees
ADD Department VARCHAR(50);
-Renaming a column:
ALTER TABLE Employees
RENAME COLUMN Department to DeptName;
3. DROP:
DROP removes an existing object from the database.
You can drop tables, views, indexes, or other objects.
Use it with caution, as it permanently deletes data and structures.
Example in SQL statements
DROP TABLE Employees;
4. TRUNCATE:
TRUNCATE removes all records from a table, freeing up space.
Unlike DELETE, it doesn’t log individual deletions, making it faster.
Note that it doesn’t remove the table structure itself.
Example in SQL Statement:
TRUNCATE TABLE Employees;
(b) Using SQL (Data Manipulation Language (DML)) to manipulate tables
For data manipulation you’ll use the DML commands below; 1. INSERT.
Use INSERT INTO to add new rows to a table.
Example using SQL statement
Syntax: INSERT INTO table-name (column1, column2, ..., columnN)
VALUES (value1, value2, ..., valueN);
INSERT INTO Employees (EmployeeID, FullName, Occupation, Age, Monthly
UPDATE Employees SET Department = 'Finance' WHERE EmployeeID = 101; 3. QUERY: Use SELECT to retrieve data from one or more tables.
Example in SQL Statements
SELECT FirstName, LastName
FROM Employees; 4. DELETE: The DELETE command removes records from tables. Example in SQL Statement DELETE FROM table-name WHERE condition; DELETE FROM Employees WHERE EmployeeID = 'BCA1003'; 5. SELECT: The SELECT command retrieves data from a specific table Syntax: SELECT column1, column2, ..., column5 FROM table name; Example: Retrieve all values from the “Employees” table: SELECT * FROM Employees: