Lab-10 Mplementation of DML Commands in SQL__ __Objective___ - To Perform Calculations on Data Values. - To Group Data Rows Based on Specific Column Values. - To Filter Grouped Data Based on Specific Conditions. - To Sort the Result Set
Lab-10 Mplementation of DML Commands in SQL__ __Objective___ - To Perform Calculations on Data Values. - To Group Data Rows Based on Specific Column Values. - To Filter Grouped Data Based on Specific Conditions. - To Sort the Result Set
Lab Objective:
This lab aims to equip students with practical skills in implementing different types of
keys in SQL. Students will learn how to define and use keys such as primary keys,
foreign keys, unique keys, and composite keys to enforce data integrity and establish
relationships between tables.
Prerequisites:
● A foundational understanding of relational databases and SQL syntax.
● Familiarity with basic SQL operations such as creating and altering tables.
● Access to an SQL environment (e.g., MySQL, PostgreSQL, SQL Server).
Lab Exercises:
1. Creating a Table with a Primary Key
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY NOT NULL,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE NOT NULL
);
● The CustomerID column is set as the Primary Key, ensuring each customer has a
unique identifier.
● The Email column is defined as Unique, preventing duplicate entries.
● The SKU column is designated as Unique, ensuring no two products have the
same SKU.
● This will fail due to the Foreign Key constraint, as OrderID 999 does not exist.
Outcome:
Upon completing this lab, students will: