I'm not so familiar with SQL. I have a table with over 100 columns. What is the best way to insert data from a dictionary into the corresponding column of my table (key and column names are identical)?
Example:
My SQL Table
Column1 Column2 Column3 Column4 Column5
My data which I get from a dictionary:
First Data set
Column2:apple, Column4:tree
Second Data set
Column1:banana, Column2:blue, Column3:green, Column4:house, Column5:red
So if the key of the dictionary is identical to the column name of the table, the data should be inserted. I know how to do this for a single query but how can I do this (clever) for a large number of queries?
Thanks!
Edit:
What I would do at a single level and some clarifications:
1) Create a SQL Table with all 120 columns but without any data. 2) I have about 500 word files which contain a part of the data which should go into the database (about 5-10 from the 120 columns). 3) So I have to read them, parse them and if the key of the data in the dictionary match any of the 120 column names, the value should be inserted. 3) Single mode:
if key == 'Column1':
sql = INSERT INTO Column1 valuexy
This is of course very stupid for 500 files and 120 columns. I hope this was more clear.