sqliteHow do I insert data into a SQLite database?
To insert data into a SQLite database, follow the steps below:
- Connect to the SQLite database using the
sqlite3
Python module.
import sqlite3
connection = sqlite3.connect("mydatabase.db")
cursor = connection.cursor()
- Create a SQL statement to insert the data into the table.
sql_statement = "INSERT INTO users (name, email) VALUES (?, ?)"
- Execute the statement with the data to be inserted.
cursor.execute(sql_statement, ("John Doe", "[email protected]"))
- Commit the changes to the database.
connection.commit()
- Close the connection to the database.
connection.close()
For more information, see the SQLite Documentation and the Python SQLite3 Tutorial.
More of Sqlite
- How do I use SQLite with Zephyr?
- How do I list all tables in a SQLite database?
- How do I download and install SQLite zip?
- How do I set up an ODBC driver to connect to an SQLite database?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I format a date in SQLite using the YYYYMMDD format?
- How do I use SQLite xfilter to filter data?
- How to configure SQLite with XAMPP on Windows?
- How can I use SQLite to query for records between two specific dates?
- How do I use the SQLite sequence feature?
See more codes...