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 can SQLite and ZFS be used together for software development?
- How do I use SQLite transactions?
- How can I use SQLite to query for records between two specific dates?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I use SQLite Expert Personal to create a database?
- How can I use SQLite with Xamarin?
- How to configure SQLite with XAMPP on Windows?
- How do I use SQLite with Visual Studio?
- How do I use SQLite to retrieve data from a specific year?
- How can I use SQLite with WPF?
See more codes...