First, I am a final year software engineering student. We are creating a KPI software. In there, the inputs can be either CSV, txt, xml or excel. When user enter the file to the software, we have to dynamically create a table for that particular file, to store data.
I have created a “File Import Wizard” to import files. Now the problem is creating tables. Lets say following is the data file I received as .txt
Name,Age,Address
Shaun,22,NY
Milan,21,Dexel RD
Now in the wizard I have already identified the fields of the table (columns) are Name, Age, and Address. But when I create the table dynamically, do I have to let the user to set the data type of each and every field?
eg: Name - Text
Age - Numbers
Address - Text
But since we don’t know how many fields a table may have, this will be a very hard task.
what I have planned is to store all the data as ‘VarChar’. Because you know, String can be converted back to other data types easily (Numbers, date).
So when the user wants to display the data in Charts, we can get the data in table and convert them into required data types and do neccasary calculations.
What is your advice on this? Please help.
Your database is supposed to contain data – if your data will be treated like a string (entered like a string, displayed as a string, manipulated as a string) storing it as a string would be fine.
On the other hand, if you will be treating your data a different way at some point (say you want to select from a calendar a date), it makes sense to convert your data before putting it in the database. In this case, if you don’t convert it now, you’ll be kicking the can down the road and it’ll cause more headache later.
If you’re in the second situation, consider reading the file header (and perhaps first row) in, and providing them with applicable choices for each row (you could even pragmatically take a best guess). That way the user gets the final say as to what kind of data should be uploaded. Perhaps something like this: