Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE student _ registration _ system; CREATE TABLE departments ( department _ id INT PRIMARY KEY AUTO _ INCREMENT, department _ name VARCHAR ( 1

USE student_registration_system;
CREATE TABLE departments (
department_id INT PRIMARY KEY AUTO_INCREMENT,
department_name VARCHAR(100)
);
CREATE TABLE students (
student_id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(100),
last_name VARCHAR(100),
department_id INT,
FOREIGN KEY (department_id) REFERENCES departments(department_id)
); CREATE TABLE courses (
course_id INT PRIMARY KEY AUTO_INCREMENT,
course_name VARCHAR(100)
);
CREATE TABLE registrations (
registration_id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT,
course_id INT,
registration_date DATE,
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
); BASED ON THE RELATION DATABASE PROVIDED ABOVE, CREATE CODES FOR STUDENT REGISTRATION SYSTEM THAT WILL CREATE A GUI USING THE BELLOW INFORMATION. GIVE COMPLETE CODES AND ALSO GIVE COMPLETE CODES FOR INSERT,DELETE,UPDATE AND GET FUNCTIONS. Give correct codes for each step and DESCRIBE THE FUNCTIONALITY. NOTE: USE Python and MySQL workbeanch my_cursor = mydb.cursor()
def insert():
first_name = e_first_name.get()
last_name = e_last_name.get()
department_id = e_department_id.get()
if first_name =="" or last_name =="" or department_id =="":
messagebox.showinfo("Insert status", "All fields are required")
else:
my_cursor.execute("INSERT INTO students (first_name, last_name, department_id) VALUES (%s,%s,%s)",
(first_name, last_name, department_id))
mydb.commit()
e_first_name.delete(0, 'end')
e_last_name.delete(0, 'end')
e_department_id.delete(0, 'end')
messagebox.showinfo("Insert status", "Insert successful")
def delete():
student_id_to_delete = get_student_id()
if student_id_to_delete is not None:
my_cursor.execute("DELETE FROM students WHERE student_id =%s",(student_id_to_delete,))
mydb.commit()
messagebox.showinfo("Delete status", "Deletion successful")
def update():
student_id_to_update = get_student_id()
if student_id_to_update is not None:
first_name = e_first_name.get()
last_name = e_last_name.get()
department_id = e_department_id.get()
my_cursor.execute("UPDATE students SET first_name=%s, last_name=%s, department_id=%s WHERE student_id=%s",
(first_name, last_name, department_id, student_id_to_update))
mydb.commit()
messagebox.showinfo("Update status", "Update successful")
def get():
student_id_to_fetch = get_student_id()
if student_id_to_fetch is not None:
my_cursor.execute("SELECT * FROM students WHERE student_id =%s",(student_id_to_fetch,))
rows = my_cursor.fetchall()
for row in rows:
e_first_name.insert(0, row[1])
e_last_name.insert(0, row[2])
e_department_id.insert(0, row[3])
messagebox.showinfo("Get status", "Fetch successful")
def get_student_id():
student_id = entry_student_id.get()
return student_id
root = Tk()
root.geometry("900x500")
root.title("STUDENT REGISTRATION SYSTEM")
first_name_label = Label(root, text='First Name', font=('bold',10))
first_name_label.place(x=20, y=60)
last_name_label = Label(root, text='Last Name', font=('bold',10))
last_name_label.place(x=20, y=90)
department_id_label = Label(root, text='Department ID', font=('bold',10))
department_id_label.place(x=20, y=120)
entry_student_id = Entry()
entry_student_id.place(x=180, y=30)
e_first_name = Entry()
e_first_name.place(x=180, y=60)
e_last_name = Entry()
e_last_name.place(x=180, y=90)
e_department_id = Entry()
e_department_id.place(x=180, y=120)
insert_button = Button(root, text="Insert", font=("italic",10), bg="white", command=insert)
insert_button.place(x=20, y=180)
delete_button = Button(root, text="Delete", font=("italic",10), bg="white", command=delete)
delete_button.place(x=70, y=180)
update_button = Button(root, text="Update", font=("italic",10), bg="white", command=update)
update_button.place(x=120, y=180)
get_button = Button(root, text="Get", font=("italic",10), bg="white", command=get)
get_button.place(x=180, y=180)
root.mainloop()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions