DBMS File CS 502
DBMS File CS 502
Objective:- Learn and apply the concept of Data Definition Language (DDL)
commands in RDBMS, Data Manipulation Language (DML) and Data
Control Language (DCL).
1. Data Definition Language (DDL)
DDL commands define the structure of a database and its objects, such as tables,
indexes, and views. They focus on creating, altering, and deleting these elements.
Common DDL commands include:
● CREATE: Creates a new table, database, index, or other database object.
1. Selection
Selection involves retrieving specific rows from the table based on a condition.
2. Projection
Projection is used to retrieve specific columns from a table
3. Sorting
Sorting arranges the result set in a specific order, using ORDER BY.
4. Small-Large Number of Attributes
You can retrieve either a few or all attributes in the table.
6. Renaming Attributes
Use AS to rename columns in the output.
Combining % and _:
Example: NOT IN (Retrieve employees who are not assigned to any project.)
Example: EXISTS (Retrieve employees who belong to a department that has a project.)
Example: NOT EXISTS (Retrieve departments that have no employees.)
1. Union
The UNION operation combines rows from two tables, removing duplicates, and returns
all unique rows from both queries. Let’s say we want a combined list of all unique
departments and all unique project names.
2. Difference
The EXCEPT (or MINUS in some SQL dialects) operation returns rows from the first
query that are not in the second query. For example, if we want to find employees who
are not assigned to any project, we can use EXCEPT.
3. Intersection
The INTERSECT operation returns rows that are common to both tables. For instance,
we can find employees who are also assigned to at least one project.
4. Division
The DIVISION operation is useful when you want to find entities related to all entities in
another set. This is often simulated using JOIN, GROUP BY, and HAVING clauses in SQL.
Result: (Since no employee is assigned to all projects in the example, this query would
return no results in this case.)
Experiment No : 8
Objective:- PL/SQL Programming II :Creating stored procedures, functions,
Trigger
CURSOR SYNTAX
DECLARE test CURSOR FOR
Select *from employee_salary;
Open cursor_name;
FETCH [ NEXT [ FROM ] ] cursor_name INTO variable_list;
Close cursor_name;
PROCEDURE
Experiment No : 9
Objective:- Create your optimize database in a team for any given problem
Problem Statement
Design a database for a task management application for a company. The application
should manage teams, employees, projects, tasks, and task assignments. The goal is
to track which employees are working on which tasks, the tasks’ statuses, and the
projects they belong to.
Step-by-Step Plan to Create the Optimized Database
Step 1: Requirements Gathering & Analysis
● Identify the key entities in the system: Teams, Employees, Projects, Tasks, Task
Assignments, Task Statuses.
● Determine relationships between these entities.
● Identify the main queries that the application will use, as these will influence the
design.
Example questions to ask:
● How are tasks assigned to employees?
● Can multiple employees work on a single task?
● Can employees belong to multiple teams?
● What are the various statuses for a task (e.g., Pending, In Progress, Completed)?
Step 2: Create an ER Diagram
The Database Architect creates an ER Diagram that outlines the entities and their
relationships. A preliminary design could look like this:
1. Teams - Represents different teams within the company.
2. Employees - Each employee has a role and is associated with one or more
teams.
3. Projects - Projects that are managed by different teams.
4. Tasks - Each project has multiple tasks associated with it.
5. Task Assignments - Links employees to tasks to track who is working on what.
6. Task Statuses - Defines the status of each task (e.g., Pending, In Progress,
Completed).
Step 3: Define Database Schema
The Database Architect and Developer work together to create the schema. Here’s a
sample schema for each table:
The Data Analyst and Database Architect work together to ensure the schema is
normalized, which involves:
1. Removing duplicate data (1NF - First Normal Form).
2. Ensuring relationships through foreign keys (2NF - Second Normal Form).
3. Removing transitive dependencies to avoid redundancy (3NF - Third Normal
Form).
In this case:
● All columns are atomic.
● Foreign keys ensure data is related but not duplicated.
● Separate tables for Task Statuses and Task Assignments help avoid redundant
data.
Step 5: Indexing and Query Optimization
The DBA and Data Analyst should also identify potential performance bottlenecks and
create optimized views or materialized views for complex reports.
The QA Engineer tests the database schema for correctness by running sample queries
and verifying results. Load testing is also performed to see how the database handles
concurrent connections and large datasets.
Example testing queries:
Step 8: Documentation and Handover
The team documents the database structure, optimizations, and access control
policies. This documentation should include:
● ER Diagram showing the database structure and relationships.
● Schema definition and any specific optimizations.
● Permissions and access controls.
● Maintenance Plan including backup, recovery, and indexing strategies.