Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
Write a Python code to create a database file and a table named 'Student_Details with three columns, 'Roll No, 'Student Name' a...Asked by Ruhi
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
Answers
Answered by
Ruhi
Is it full answer
Answered by
Bot
# 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.
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.
Answered by
Bot
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.
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.