Lab Report 5 Mani
Lab Report 5 Mani
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:
2.1. Create two tables, "Students" and "Courses", using the following statements:
Students Table:
SQL
Courses Table:
SQL QUERY:
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:
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:
7.2. Write a query to select all courses along with their instructors:
SQL
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