The DB2 database system created by IBM operates on Window and Linux machines and can import file types such as comma separated value (CSV) files. This allows you to create your data in a separate program and upload it directly into your DB2 tables to save time. DB2 offers a few options for uploading files. The command center provides a direct option, but importing CSV files via SQL commands allows you to manipulate or change the data before you add it to the table.
SQL Command
Video of the Day
Step 1
Open the SQL code for your DB2 database and connect to the database.
Video of the Day
Step 2
Type "IMPORT FROM "sample_file.csv" OF DEL INSERT INTO your_table (attribute1, attribute2)" into the code replacing "sample_file.csv" with the path and name of your CSV file, "your_table" with the name of the table you want to import the data into and "attribute1" and "attribute2" with the names of the columns. You may import as many attributes as you need as long as you separate them with commas.
Step 3
Run the code and check your table to see that the data from the CSV file has imported correctly.
Command Center
Step 1
Click the "Start" icon, open "All Programs," open the "IBM DB2" folder and click "Command Center."
Step 2
Click "File" or "Command Center" in the top toolbar menu. Click "Import," then click "..." to browse for the file. Click "OK" to complete the process. You can also right-click with the left-hand navigation tree and click "Create from Import" to access the same options.
Step 3
Refresh the table and check the data for any errors.