Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

BCA -II year practical DBMS using SQL

The document outlines the design and implementation of a University Management System database, including the creation of tables for departments, instructors, courses, students, and enrollments. It provides SQL commands for creating tables, inserting data, displaying data, and modifying table structures. Additionally, it includes examples of simple SQL queries and the use of aggregate functions to analyze enrollment data.

Uploaded by

Sara Haha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

BCA -II year practical DBMS using SQL

The document outlines the design and implementation of a University Management System database, including the creation of tables for departments, instructors, courses, students, and enrollments. It provides SQL commands for creating tables, inserting data, displaying data, and modifying table structures. Additionally, it includes examples of simple SQL queries and the use of aggregate functions to analyze enrollment data.

Uploaded by

Sara Haha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

INDEX

1.To draw ER model and relational model for a given database design for University
Management system for relational model design?

2. Implementation of database to create new table, insert, display.

3. Create a data definition modification using its all commands

4.Simple SQL queries (single table retrieval).

5. Create a database using aggregate function.


1.To draw ER model and relational model for a given database design for University
Management system?
Ans: -- Department Table
CREATE TABLE Department (
Department_ID INT PRIMARY KEY,
Department_Name VARCHAR(100)
);

-- Instructor Table
CREATE TABLE Instructor (
Instructor_ID INT PRIMARY KEY,
Name VARCHAR(100),
Department_ID INT,
FOREIGN KEY (Department_ID) REFERENCES Department(Department_ID)
);

-- Course Table
CREATE TABLE Course (
Course_ID INT PRIMARY KEY,
Course_Name VARCHAR(100),
Credits INT,
Instructor_ID INT,
FOREIGN KEY (Instructor_ID) REFERENCES Instructor(Instructor_ID)
);

-- Student Table
CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
Name VARCHAR(100),
DOB DATE,
Email VARCHAR(100)
);

-- Enrolls Table (M:N Relationship between Student and Course)


CREATE TABLE Enrolls (
Student_ID INT,
Course_ID INT,
PRIMARY KEY (Student_ID, Course_ID),
FOREIGN KEY (Student_ID) REFERENCES Student(Student_ID),
FOREIGN KEY (Course_ID) REFERENCES Course(Course_ID)
);

Output:
2. Implementation of database to create new table, insert, display.
Ans:- Step 1: Create a Database:
Step 2: Create Tables
Create Student Table
CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
Name VARCHAR(100),
DOB DATE,
Email VARCHAR(100)
);
-- Create Course Table
CREATE TABLE Course (
Course_ID INT PRIMARY KEY,
Course_Name VARCHAR(100),
Credits INT
);
-- Create Enrollment Table (Many-to-Many relationship)
CREATE TABLE Enrollment (
Student_ID INT,
Course_ID INT,
PRIMARY KEY (Student_ID, Course_ID),
FOREIGN KEY (Student_ID) REFERENCES Student(Student_ID),
FOREIGN KEY (Course_ID) REFERENCES Course(Course_ID)
);
Step 3: Insert Data into Tables-- Insert data into Student Table
INSERT INTO Student (Student_ID, Name, DOB, Email)
VALUES
(1, 'John Doe', '2000-01-15', 'john.doe@email.com'),
(2, 'Jane Smith', '1999-02-22', 'jane.smith@email.com'),
(3, 'Robert Brown', '2001-03-10', 'robert.brown@email.com');

-- Insert data into Course Table


INSERT INTO Course (Course_ID, Course_Name, Credits)
VALUES
(101, 'Mathematics', 3),
(102, 'Physics', 4),
(103, 'Computer Science', 3);

-- Insert data into Enrollment Table


INSERT INTO Enrollment (Student_ID, Course_ID)
VALUES
(1, 101),
(1, 102),
(2, 102),
(3, 103);
Step 4: Display Data from Tables
-- Display data from Student table
SELECT * FROM Student;

-- Display data from Course table


SELECT * FROM Course;

-- Display data from Enrollment table


SELECT * FROM Enrollment;
Output:
3. Create a data definition modification using its all commands .
Ans: Add a New Column to a Table
Suppose we want to add a Phone_Number column to the Student table.
ALTER TABLE Student
ADD Phone_Number VARCHAR(15);
Drop a Column from a Table
Now, let's say we want to remove the Email column from the Student table.
ALTER TABLE Student
DROP COLUMN Email;
Rename a Column:
ALTER TABLE Student
RENAME COLUMN Name TO Full_Name;
Rename a Table
If we want to rename the Course table to Courses_Offered, we can do so as follows:
ALTER TABLE Course
RENAME TO Courses_Offered;
4.Simple SQL queries (single table retrieval).
Ans:
5. Create a database using aggregate function.
Ans: We will use aggregate functions like COUNT(), SUM(), and AVG() to retrieve useful
data.
Count the Total Number of Students Enrolled in Each Course:
SELECT Course_ID, COUNT(Student_ID) AS Number_Of_Students
FROM Enrollment
GROUP BY Course_ID;

You might also like