Intro to DB_6 lab 06 umer
Intro to DB_6 lab 06 umer
Lab#6
Objective:
Signature: _____________________________
1
Lab No 6
EXERCISES
Consider the following schema, in the form of normalized relations, to represent information
about employees, grades, training and projects in an organization.
EMPLOYEE GRADE
Empno (eg 6712) Designation
Name Grade (1-20)
Designation (e.g. Database Developer) TotalPosts
Qualification PostsAvailable (<= TotalPosts)
Joindate
PROJECT TRAINING
PID (eg P812) Tcode (eg T902)
Title Title
Client StartDate
Duration (in weeks) EndDate
Status (New, In Progress, Complete)
EMP_PROJECT EMP_TRAINING
Empno Empno
PID Tcode
Performance (Excellent, Good, Fair, Bad, Poor) Attendance (%)
1. Develop a script file EMPLOYEE.SQL to create tables for the above schema. Implement
all necessary integrity constraints including primary and foreign keys. (NOTE: All check
constraints should be at table level)
EMPLOYEE TABLE
2
Lab No 6
GRADE TABLE
PROJECT TABLE
3
Lab No 6
TRAINING TABLE
EMP_PROJECT TABLE
4
Lab No 6
EMP_TRAINING TABLE
5
Lab No 6
3. What is database schema? What are the different objects included in it?
A database schema is the logical structure or blueprint of a database that defines how data is
organized and how the relationships between data are managed. It includes a set of rules and
constraints that specify the organization of tables, columns, keys, indexes, and other elements
within the database. The schema provides a detailed framework for how the database operates and
serves as a guide for developers and database administrators.
It does not include the actual data but focuses on the metadata and structure.
1. Tables
● Definition: The primary structure in a schema where data is stored in rows and columns.
Example:
CREATE TABLE Employee (
Emp_ID INT PRIMARY KEY,
FullName VARCHAR(150),
JobTitle VARCHAR(100)
);
2. Views
● Definition: A virtual table that is based on the result set of a query. It does not store data
itself but provides a way to access or aggregate data from one or more tables.
Example:
3. Indexes
● Definition: Used to improve the speed of data retrieval by creating quick access paths to
data in tables.
Example:
CREATE INDEX idx_emp_fullname ON Employee (FullName);
6
Lab No 6
4. Keys
● Types:
○ Primary Key: Ensures that each row in a table is unique.
○ Foreign Key: Establishes a relationship between two tables.
○ Unique Key: Ensures that values in a specific column are unique.
Example:
5. Constraints
Example:
6. Stored Procedures
● Definition: Precompiled SQL code that can be executed as a single unit to perform
operations like insert, update, or calculations.
Example:
7
Lab No 6
7. Functions
● Definition: Similar to stored procedures but returns a single value and is used for
calculations.
Example:
8. Triggers
● Definition: Code that automatically executes in response to certain events (e.g., insert,
update, delete) in a table.
Example:
9. Sequences
● Definition: Generates unique numeric values, often used for auto-incrementing primary
keys.
Example:
10. Synonyms
● Definition: Alias names for database objects like tables, views, or procedures.
Example:
8
Lab No 6
1. Physical Schema: Defines how data is stored at the physical level, including storage
details like file organization.
2. Logical Schema: Represents the logical structure of the database (e.g., tables,
relationships).
3. View Schema: Defines how data is presented to users, such as via views.
The database schema is critical in ensuring that the database is consistent, maintains integrity, and
aligns with business rules.