How to create a SQLite database to store data for students, courses, faculty, departments, and grades ? And how can you connect it to your project work using your Python code?

SQLite :

We will first learn about the MySQL database and then gradually comprehend each of its processes.

This brings us to the question: What is SQLite?

Definition: A serverless, lightweight, stand-alone relational database management system (RDBMS) is called SQLite. Although SQLite is not a component of the Django framework, it is the default database that it uses. When using SQL commands to manage data, SQLite can be used without Django.

Processes:

Using Python and SQLite as the database, the system might be structured as follows:

  1. Construct the database: To store information about students, departments, faculty, courses, and grades, create a SQLite database.
  2. Create tables:
  • Students: student_idstudent_namestudent_email
  • Courses: course_idcourse_name course_credits
  • Faculty: faculty_idfaculty_namefaculty_email
  • Departments: department_iddepartment_name
  • Grades: student_idcourse_id grade

3. Implementation of basic create, remove, update, and delete operations (these are also known as CRUD operations)

  • Create/Remove/Update/delete Students, Courses, Faculty, Departments, and Grades.
  • Note: If the student exits courses, faculty department grades are already in the table.#Create Students Table
    CREATE Table
    student_id INTEGER PRIMARY KEY,
    student_name TEXT NOT NULL,
    student_email TEXT UNIQUE NOT NULL
    );#Create Courses Table
    CREATE Table
    course_id INTEGER PRIMARY KEY,
    course_name TEXT NOT NULL,
    course_credits INTEGER NOT NULL
    );#Create Faculty Table
    CREATE Table
    faculty_id INTEGER PRIMARY KEY,
    faculty_name TEXT NOT NULL,
    faculty_email TEXT unique, NOT NULL
    );

    #Create Departments Table
    CREATE Table
    department_id INTEGER PRIMARY KEY,
    department_name TEXT NOT NULL
    );

    #Create Grades Table
    CREATE Table
    student_id INTEGER,
    course_id INTEGER,
    grade TEXT NOT NULL,
    PRIMARY KEY (student_id, course_id),
    FOREIGN KEY (student_id) REFERENCES Students(student_id),
    FOREIGN KEY (course_id) REFERENCES Courses(course_id)
    );

4. Python Code:

import codespeedy1

# Connect to the SQLite database (or create it if it doesn’t exist)
conn = codespeedy1.connect (‘intern.db’)
cursor = conn.cursor()

# Create Students table
cursor.execute (”’
CREATE Table
student_id INTEGER PRIMARY KEY,
student_name TEXT NOT NULL,
student_email TEXT UNIQUE NOT NULL
)
”’)

# Create Courses table
cursor.execute (”’
CREATE TABLE Courses
course_id INTEGER PRIMARY KEY,
course_name TEXT NOT NULL,
course_credits INTEGER NOT NULL
)
”’)

# Create Faculty table
cursor.execute(”’
CREATE TABLE Faculty (
faculty_id INTEGER PRIMARY KEY,
faculty_name TEXT NOT NULL,
faculty_email TEXT unique, NOT NULL
)
”’)

# Create Departments table
cursor.execute(”’
CREATE TABLE  Departments
department_id INTEGER PRIMARY KEY,
department_name TEXT NOT NULL
)
”’)

# Create Grades table
cursor.execute(”’
CREATE TABLE Grades
student_id INTEGER,
course_id INTEGER,
grade TEXT NOT NULL,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES Students(student_id),
FOREIGN KEY (course_id) REFERENCES Courses(course_id)
)
”’)

# Commit the changes and close the connection
conn.commit()
conn.close()

print(“Tables created successfully.”)

 

Thank you for visiting my page!

Regards

@CodespeedyIntern

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top