Up to this point my company has had an aversion to databases and has stuck to storing all data in comma-separated files. I have run into a unique customer application that – I believe – would benefit from the use of a relational database. The application calls for storing ‘summary’ data concerning a manufacturing process and ‘detailed’ data on multiple sub-processes. The sub processes need to be linked to the process summary.
My question: Is it normal/appropriate to check for the existence of a table prior to writing to this table, and creating it if the table does not exist? This may lead to a larger question now that I’m typing this; if the database does not exist, should I be creating the database and any tables that it requires?
With SQLite, creating the tables yourself is a good approach. You don’t need to be making your installation instructions for your customers any more complex than they already are, and if the database is entirely internal to your application, they probably don’t even care what format it is in, so long as your software is reliable and fast.
Firefox, for example, uses SQLite for its internal storage these days, and they never bother the user to create databases. And users like it that way. 🙂
But I wouldn’t worry too much about creating the database immediately prior to referencing the tables: instead, I would place the creation logic at application startup or installation time, whichever is more appropriate. Where are the CSV files created in your application now? Are they created afresh, every single time they are referenced? Or are they created in initialization or installation routines too?