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

Dms Code

dms code

Uploaded by

kishorgaikar876
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)
16 views4 pages

Dms Code

dms code

Uploaded by

kishorgaikar876
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

1.

Database Setup
sql
Copy code
CREATE DATABASE StudentManagement;

USE StudentManagement;

2. Tables Creation
Students Table
sql
Copy code
CREATE TABLE Students (
StudentID INT PRIMARY KEY AUTO_INCREMENT,
FirstName VARCHAR(50),
LastName VARCHAR(50),
DateOfBirth DATE,
Email VARCHAR(100)
);
Courses Table
sql
Copy code
CREATE TABLE Courses (
CourseID INT PRIMARY KEY AUTO_INCREMENT,
CourseName VARCHAR(100),
Credits INT
);
Enrollments Table
sql
Copy code
CREATE TABLE Enrollments (
EnrollmentID INT PRIMARY KEY AUTO_INCREMENT,
StudentID INT,
CourseID INT,
EnrollmentDate DATE,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
3. Sample Data Insertion
Inserting Students
sql
Copy code
INSERT INTO Students (FirstName, LastName, DateOfBirth, Email)
VALUES
('John', 'Doe', '2000-01-15', 'john.doe@example.com'),
('Jane', 'Smith', '2001-02-20', 'jane.smith@example.com');
Inserting Courses
sql
Copy code
INSERT INTO Courses (CourseName, Credits)
VALUES
('Database Systems', 3),
('Web Development', 4);
Inserting Enrollments
sql
Copy code
INSERT INTO Enrollments (StudentID, CourseID, EnrollmentDate)
VALUES
(1, 1, '2023-09-01'),
(1, 2, '2023-09-01'),
(2, 1, '2023-09-02');
4. Basic Queries
Retrieve all students
sql
Copy code
SELECT * FROM Students;
Retrieve all courses
sql
Copy code
SELECT * FROM Courses;
Retrieve enrollments
sql
Copy code
SELECT
e.EnrollmentID,
s.FirstName,
s.LastName,
c.CourseName,
e.EnrollmentDate
FROM
Enrollments e
JOIN
Students s ON e.StudentID = s.StudentID
JOIN
Courses c ON e.CourseID = c.CourseID;
5. Updating Records
Update a Student’s Email
sql
Copy code
UPDATE Students
SET Email = 'john.newemail@example.com'
WHERE StudentID = 1;
6. Deleting Records
Delete an Enrollment
sql
Copy code
DELETE FROM Enrollments
WHERE EnrollmentID = 1;

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