I developed my database by hand, and now have my app running on my development PC.
When it is deployed on a new machine, I want it to create the d/b structure if it is not already present.
So, I used SHOW CREATE TABLE ... and copied the outputs into some MySQl commands CREATE TABLE IF NOT EXISTS ... which is executed when my app starts, one command for each table.
However, although the data tables should be empty on a new PC – there is one configuration table (with a single row) which I want to populate to default values if not already present.
What’s the simplest (most elegant?) way to do that? SELECT * from the table and check row count against zer0, inserting defaults if necessary?
Is there something simpler (or “better”)? What is standard practise?
Thanks
I don’t think there’s any more elegant way to do it than you already suggested: if num_rows==0, insert data! Nothing there could be simplified.