0% found this document useful (0 votes)
5 views3 pages

DBMS PR 2

The document provides SQL commands to create two tables: Students and Courses, along with their respective fields. It includes instructions to insert 10 records into each table, delete a specific student, and count the total number of students and courses, as well as calculate the average credits for courses. Additionally, it contains sample SQL queries for each of these operations.

Uploaded by

Arpita Siddhanti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

DBMS PR 2

The document provides SQL commands to create two tables: Students and Courses, along with their respective fields. It includes instructions to insert 10 records into each table, delete a specific student, and count the total number of students and courses, as well as calculate the average credits for courses. Additionally, it contains sample SQL queries for each of these operations.

Uploaded by

Arpita Siddhanti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2.

Create Tables:

Students student_id (INT, Primary Key) first_name (VARCHAR) last_name (VARCHAR)


gender (VARCHAR) email (VARCHAR)

Courses course_id (INT, Primary Key) course_name (VARCHAR) course_code (VARCHAR)


credits (INT)

NOTE:Insert 10 records

5. Write a query to delete Student 2 (Jane Smith) from the Students table.

6. Write a query to count the total number of students in the Students table.

7. Write a query to count the total number of courses in the Courses table.

8. Write a query to find the average number of credits across all courses in the Courses
table.

CREATE TABLE Student1 (

student_id INT PRIMARY KEY,

first_name VARCHAR(50),

last_name VARCHAR(50),

gender VARCHAR(10),

email VARCHAR(100)

);

-- Insert 10 records into Student1

INSERT INTO Student1 (student_id, first_name, last_name, gender, email) VALUES

(1, 'John', 'Doe', 'Male', '[email protected]'),

(2, 'Jane', 'Smith', 'Female', '[email protected]'),

(3, 'Michael', 'Brown', 'Male', '[email protected]'),

(4, 'Emily', 'Johnson', 'Female', '[email protected]'),

(5, 'Chris', 'Davis', 'Male', '[email protected]'),


(6, 'Sarah', 'Miller', 'Female', '[email protected]'),

(7, 'David', 'Wilson', 'Male', '[email protected]'),

(8, 'Laura', 'Taylor', 'Female', '[email protected]'),

(9, 'Daniel', 'Anderson', 'Male', '[email protected]'),

(10, 'Olivia', 'Thomas', 'Female', '[email protected]');

CREATE TABLE Courses1 (

course_id INT PRIMARY KEY,

course_name VARCHAR(100),

course_code VARCHAR(20)

);

INSERT INTO Courses1 (course_id, course_name, course_code) VALUES

(1, 'Introduction to Computer Science', 'CS101'),

(2, 'Calculus I', 'MATH101'),

(3, 'Physics I', 'PHY101'),

(4, 'English Literature', 'ENG201'),

(5, 'World History', 'HIST101'),

(6, 'Chemistry I', 'CHEM101'),

(7, 'Principles of Economics', 'ECON101'),

(8, 'Psychology 101', 'PSY101'),

(9, 'Software Engineering', 'CS301'),

(10, 'Art Appreciation', 'ART101');


5. Write a query to delete Student 2 (Jane Smith) from the Students table

DELETE FROM Student1

WHERE student_id = 2;

6. Write a query to count the total number of students in the Students table.

SELECT COUNT(*) AS total_students

FROM Student1;

7. Write a query to count the total number of courses in the Courses table.

SELECT COUNT(*) AS total_courses

FROM Courses1;

8. Write a query to find the average number of credits across all courses in the Courses

table.

SELECT AVG(credits) AS average_credits

FROM Courses;

You might also like