Introduction to database – Tutorial 02 –
Exercises
1. Create a Database:
CREATE DATABASE StudentDB;
2. List All Databases:
SHOW DATABASES;
3. Use and Drop a Database:
• Use the "StudentDB" database:
USE StudentDB;
• Drop (delete) the "StudentDB" database:
DROP DATABASE StudentDB;
4. Create Tables:
• Inside "StudentDB," create a table named "Students" with the
specified columns and data types:
CREATE TABLE Students ( StudentID INT PRIMARY KEY,
FirstName VARCHAR(50), LastName VARCHAR(50), DateOfBirth
DATE, Email VARCHAR(100), GPA DECIMAL(3, 2) );
5. List Tables:
• List all the tables in the current database ("StudentDB") to verify
that the "Students" table was created:
SHOW TABLES;
6. Describe Table:
• Describe the structure (columns and data types) of the
"Students" table:
DESCRIBE Students;
7. Drop a Table:
• Drop (delete) the "Students" table:
DROP TABLE Students;
8. Insert Values into Table:
• Insert a 10 student records into the "Students" table. For
example:
INSERT INTO Students (StudentID, FirstName, LastName,
DateOfBirth, Email, GPA) VALUES (1, 'Avinash',
'Pokharel', 1994-10-05', 'avinash.pokharel@example.com',
3.50);
9. Basic SELECT Statement:
• Write a basic SELECT statement to retrieve all records from the
"Students" table:
SELECT * FROM Students;
Make Following tables and insert 10 records in each of them:
Table: Courses
• Create a table named "Courses" with the following columns:
• CourseID (INT, Primary Key)
• CourseName (VARCHAR(100))
• InstructorName (VARCHAR(100))
• Credits (INT)
• Department (VARCHAR(50))
Table: Enrollments
• Create a table named "Enrollments" with the following columns:
• EnrollmentID (INT, Primary Key)
• StudentID (INT)
• CourseID (INT)
• EnrollmentDate (DATE)
Table: Assignments
• Create a table named "Assignments" with the following columns:
• AssignmentID (INT, Primary Key)
• CourseID (INT)
• AssignmentName (VARCHAR(100))
• Deadline (DATE)
• MaxPoints (INT)
Table: Clubs
• Create a table named "Clubs" with the following columns:
• ClubID (INT, Primary Key)
• ClubName (VARCHAR(100))
• ClubDescription (TEXT)
• MeetingDay (VARCHAR(20))
• AdvisorName (VARCHAR(100))