I'm wondering what is the best way to create and maintain databases maps and SQL scripts. I know I'm more a fan of writing the SQL script by hand on a text editor (plus designing a map to have next to me on a piece of paper), while others prefers to use database maps softwares (MySQL Workbench, Visual Studio... some listed in this post) to automatically generate the script.
Both solutions have advantages and drawbacks. I see these advantages:
What do you think, what way do you proceed?
If automating something saves time and human error why wouldn't you do it? I would try auto-generating SQL if:
Another rare case might be if you had a massive list of data sets for which the schema needed to be extracted in the form of SQL.
The benefits of writing by hand are that you are aware of every part of the design and better able to enforce data integrity (for instance through use of foreign keys or limiting data types). In short, I would agree with your list of pros.
For upgrade scripts I strongly prefer writing these by hand because they're usually fairly short and it's nice for them to be more readable for the people who end up running them.
One tip I'd have for upgrade scripts is to make sure each script adds a row stating the upgrade version number in a table which is exclusively there to ensure the database is versioned correctly. Something like:
INSERT INTO DB_VERSION (upgrade_time, version_from, version_to, comment)
VALUES ('2011-07-04T120320', '2.2.4', '2.3', 'add column x to table y.')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With