Write a Python code to create a database file and a table named 'Student_Details with three columns, 'Roll No, 'Student Name' and 'Student Class'. Support your code with suitable comments

3 answers

# import the SQLite module
import sqlite3

# Create a connection to the database file
conn = sqlite3.connect('students.db')

# Create a table named 'Student_Details' with three columns, 'Roll No', 'Student Name' and 'Student Class'
cur = conn.cursor()
cur.execute("CREATE TABLE Student_Details (Roll_No INT, Student_Name TEXT, Student_Class TEXT)")

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

# The above code will create the database file 'students.db' and the table 'Student_Details' with the given columns.
Is it full answer
Yes, the above code creates a database file named 'students.db' and a table named 'Student_Details' with three columns: 'Roll_No', 'Student_Name', and 'Student_Class'. The code establishes a connection to the database, creates a cursor object, executes the SQL statement to create the table, and commits the changes. Finally, the connection to the database is closed.