Export the data of a table as CSV
To export data from an SQLite table to a CSV file, you can use the following methods:
๐ Method 1: Using SQLite Command Line
- Open your SQLite database in the terminal:
- Set output mode to CSV:
- Set the output file name:
- Run the query to export:
- Exit SQLite:
✅ Now, my_table_data.csv will contain your table data in CSV format.
๐ Method 2: Using SQL Query
If you're inside SQLite, run:
This exports data with column headers.
๐ Method 3: Using Python
If you prefer Python, use the csv module:
✅ This will create my_table_data.csv with column headers.
๐ Check Your Exported CSV
After exporting, verify the data using:
or
Let me know if you need further help! ๐๐
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Import the CSV data into an SQLite table
To import CSV data into an SQLite table, use one of the following methods:
๐ Method 1: Using SQLite Command Line
- Open your SQLite database in the terminal:
- Enable CSV mode:
- Import the CSV file into the table:
- Verify the data:
✅ Your CSV data is now imported into my_table.
๐ Method 2: Using Python
If you prefer Python, use the csv module:
✅ This script reads my_data.csv and inserts it into my_table.
๐ Method 3: Using Pandas (If You Have Large Data)
If you're dealing with large CSV files, use pandas:
✅ Best for handling large datasets efficiently.
๐ Verify Import
Run this in SQLite to check your data:
Let me know if you need further help! ๐๐
No comments:
Post a Comment