• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 3 fuera de 27 páginas
Notas de lectura

Lab Notes Keys & Constraints | DBMS MySQL | 2026/27

Document preview thumbnail
Vista previa 3 fuera de 27 páginas

Laboratory notes from the Database Management Systems course covering keys and constraints in relational databases. The document details Primary Keys, Foreign Keys, UNIQUE and NOT NULL constraints, with practical exercises completed in MySQL Workbench including table creation, constraint implementation, and violation testing. Includes worked examples, constraint testing tables, and output-based Q&A that directly reflect the lab activities—useful for understanding data integrity concepts and preparing for DBMS assessments.

Vista previa del contenido

DATABASE SYSTEMS LAB MANUAL



Keys & Constraints
Topic: Primary Key, Foreign Key, UNIQUE, NOT NULL, and Data Integrity
1. Objective:
By the end of this lab, you will be able to:
 Understand the purpose of keys and constraints in relational databases.
 Explain the concept of a Primary Key.
 Explain the concept of a Foreign Key.
 Understand the purpose of the UNIQUE constraint.
 Understand the purpose of the NOT NULL constraint.
 Understand entity integrity and referential integrity.
 Create tables with appropriate constraints using SQL.
 Implement Primary Key and Foreign Key relationships.
 Apply UNIQUE and NOT NULL constraints.
 Test valid and invalid data using MySQL Workbench.
 Analyze constraint violations and explain why they occur.




2. HARDWARE AND SOFTWARE REQUIRED:
Hardware
 PC or Laptop
 Keyboard and Mouse
 Minimum 4 GB RAM
 Internet connection
Software
 MySQL Server
 MySQL Workbench
 Windows / Linux / macOS
Other Requirements
 Access to LMS
 Previous Lab database knowledge
 Folder for saving screenshots
 Basic SQL knowledge


3. INTRODUCTION
In a relational database, data is stored in tables.
For example, a university database may contain:
Students
Courses
Departments
Teachers
1|Page

,DATABASE SYSTEMS LAB MANUAL
Enrollments
When data is stored in multiple tables, we need rules to make sure that the data remains:
 Correct
 Valid
 Consistent
 Unique where required
 Properly connected between tables
These rules are implemented using keys and constraints.

4. WHAT IS A KEY?
A key is an attribute or a set of attributes used to identify records or establish relationships between
tables.

For example:
Student_ID Student_Name Program
101 Ali BSCS
102 Sara BSAI
103 Ahmed BSSE

Here, Student_ID can be used to uniquely identify each student.




5. PRIMARY KEY
A Primary Key is a column or combination of columns that uniquely identifies each record in a
table.
A Primary Key:
 Must contain unique values.
 Cannot contain NULL.
 Identifies each record.
 A table normally has one Primary Key definition.

Example:
CREATE TABLE Students (
Student_ID INT PRIMARY KEY,
Student_Name VARCHAR(50),
Program VARCHAR(50)
);

Here: “Student_ID” is the Primary Key.
Example Data

Student_ID Student_Name Program


2|Page

, DATABASE SYSTEMS LAB MANUAL


101 Ali BSCS


102 Sara BSAI


103 Ahmed BSSE
Every student has a different Student_ID.

6. WHY DO WE NEED A PRIMARY KEY?
Suppose a student table contains:

Student_ID Student_Name
101 Ali
101 Ahmed

Which student does ID 101 represent?
 There is ambiguity.

A Primary Key prevents this situation by requiring every value to be unique.




7. FOREIGN KEY
A Foreign Key is a column that creates a relationship between two tables.
For example:
Students:
Student_ID Student_Name
101 Ali
102 Sara
Enrollments:
Enrollment_ID Student_ID Course
1 101 DBMS
2 102 OOP
The Student_ID in the Enrollments table refers to the Student_ID in the Students table.
Therefore:

Students.Student_ID
↑
Enrollments.Student_ID

This relationship can be implemented using a Foreign Key.


3|Page

Información del documento

Estudio
Subido en
30 de octubre de 2026
Número de páginas
27
Escrito en
2026/2027
Tipo
Notas de lectura
Profesor(es)
M. huzaifa yasir khan
Contiene
Todas las clases
$7.66

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
7
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes