0% found this document useful (0 votes)
26 views4 pages

Lab Report 5 Mani

The document describes creating and populating databases and tables, adding primary and foreign keys, and performing queries. It includes SQL statements to create databases and tables, insert, update, and select data, and add keys.

Uploaded by

MANI 96 FF
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
26 views4 pages

Lab Report 5 Mani

The document describes creating and populating databases and tables, adding primary and foreign keys, and performing queries. It includes SQL statements to create databases and tables, insert, update, and select data, and add keys.

Uploaded by

MANI 96 FF
Copyright
© © All Rights Reserved
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/ 4

Name Usman Rasheed REGISTRATION B22F0497SE152

ID
COURSE Database Lab SECTION SE-GREEN
SUBMITED DR YOUSRA REHMAN DEADLINE 3-25-23
TO

LAB REPORT 05
1. Create Database:

1.1. Use the following SQL statement to create a new database named "Lab DB":

SQL QUERY:

CREATE DATABASE Lab DB;

2. Create the Tables:

2.1. Create two tables, "Students" and "Courses", using the following statements:

Students Table:

SQL

CREATE TABLE Students (


StudentID INT AUTO_INCREMENT PRIMARY KEY,
FirstName VARCHAR (255) NOT NULL,
LastName VARCHAR (255) NOT NULL,
Age INT NOT NULL
);

Courses Table:

SQL QUERY:

CREATE TABLE Courses (


CourseID INT AUTO_INCREMENT PRIMARY KEY,
CourseName VARCHAR(255) NOT NULL,
Instructor VARCHAR(255) NOT NULL
);

3. Insert Data:

3.1. Insert sample data into the "Students" table using the following statements:

SQL QUERY:

INSERT INTO Students (FirstName, LastName, Age) VALUES ('John', 'Doe', 22);
INSERT INTO Students (FirstName, LastName, Age) VALUES ('Jane', 'Smith', 20);
INSERT INTO Students (FirstName, LastName, Age) VALUES ('Mike', 'Williams', 23);
INSERT INTO Students (FirstName, LastName, Age) VALUES ('Alice', 'Johnson', 21);
INSERT INTO Students (FirstName, LastName, Age) VALUES ('Bob', 'Brown', 25);

3.2. Insert sample data into the "Courses" table using the following statements:

SQL QUERY:

INSERT INTO Courses (CourseName, Instructor) VALUES ('Programming 101', 'Mr. Smith');
INSERT INTO Students (CourseName, Instructor) VALUES ('Database Management', 'Ms.
Lee');
INSERT INTO Students (CourseName, Instructor) VALUES ('Web Development', 'Mr. Garcia');

4. Update Records:

4.1. Update the age of the student with StudentID 3 to 25 using the following statement:

SQL QUERY:

UPDATE Students SET Age = 25 WHERE StudentID = 3;

5. Primary Key:

5.1. The CourseID column in the "Courses" table is already set as the primary key using
AUTO_INCREMENT during table creation. This ensures unique identification for each course.

6. Foreign Key:

6.1. Add a foreign key constraint to the "StudentID" column in the "Courses" table referencing
the "StudentID" column in the "Students" table using the following statement:

SQL QUERY:
ALTER TABLE Courses
ADD FOREIGN KEY (StudentID) REFERENCES Students (StudentID);
.

7. Queries:

7.1. Write a query to select all students who are aged 20 or above:

SELECT * FROM Students WHERE Age >= 20;

7.2. Write a query to select all courses along with their instructors:

SQL

SELECT * FROM Courses;


8. Final Step

8.1. Taking screenshots of the queries and results is dependent on your specific SQL
environment. However, you can execute the provided queries and view the results in your
database management tool.

Screenshots

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy