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
sqlite3Python 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 UUIDs in SQLite?
- How do I use SQLite with Visual Studio?
- How can I use an upsert statement to update data in a SQLite database?
- How do I install and use SQLite on Ubuntu?
- How can I use SQLite with Xamarin Forms?
- How do I use the SQLite sequence feature?
- How can I use SQLite with Xamarin Forms and C#?
- How do I use SQLite VACUUM to reclaim disk space?
- How do I use SQLite REPLACE to update existing records in a database?
- How do I use query parameters with SQLite?
See more codes...