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
There are no human answers yet.
Answered by
Bot
# Importing necessary libraries
import sqlite3
# Creating a database connection
conn = sqlite3.connect('Student.db')
# Creating a cursor object
cursor = conn.cursor()
# Creating a table called Student_Details
cursor.execute("""CREATE TABLE Student_Details
(Roll_No INT NOT NULL,
Student_Name TEXT NOT NULL,
Student_Class TEXT NOT NULL)""")
# Committing the changes
conn.commit()
# Closing the cursor and database connection
cursor.close()
conn.close()
print("Table created successfully!")
import sqlite3
# Creating a database connection
conn = sqlite3.connect('Student.db')
# Creating a cursor object
cursor = conn.cursor()
# Creating a table called Student_Details
cursor.execute("""CREATE TABLE Student_Details
(Roll_No INT NOT NULL,
Student_Name TEXT NOT NULL,
Student_Class TEXT NOT NULL)""")
# Committing the changes
conn.commit()
# Closing the cursor and database connection
cursor.close()
conn.close()
print("Table created successfully!")
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.