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 the SQLite ZIP VFS to compress a database?
- How can I use SQLite with Zabbix?
- How do I extract the year from a datetime value in SQLite?
- How do I use SQLite xfilter to filter data?
- How do I use the SQLite zfill function?
- How to configure SQLite with XAMPP on Windows?
- How do I call sqlitepcl.raw.setprovider() when using SQLite?
- How can I write SQLite queries?
- How do I generate a UUID in SQLite?
See more codes...