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 with Zephyr?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I import data from a SQLite zip file?
- How do I use SQLite UNION to combine multiple SELECT queries?
- How do I use the SQLite zfill function?
- How do I generate a UUID in SQLite?
- How do I extract the year from a datetime value in SQLite?
- How do I generate XML output from a SQLite database?
- How to use a SQLite hash to securely store data?
See more codes...