diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/Dealing-with-SQL-files.md | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/docs/Dealing-with-SQL-files.md b/docs/Dealing-with-SQL-files.md index 8efef40..edf83d7 100644 --- a/docs/Dealing-with-SQL-files.md +++ b/docs/Dealing-with-SQL-files.md @@ -1,4 +1,6 @@ -## SQL Format +# Dealing with SQL files + +## SQL basics If you are not confident with the SQL language, we suggest to read [this tutorial](http://www.w3schools.com/sql/default.asp) before starting. @@ -12,6 +14,62 @@ Also remember to: ``UPDATE `table_name` SET `field_I_want_to_change` = 'new string value' WHERE `entry` = 10 ;`` +## Write compact code + +Compact code helps to keep the size of our SQL update files small, so installing/updating the ACDB will be faster. + +### INSERT + +Bad: + +```SQL +INSERT INTO `table_1` VALUES (1000, ...); +INSERT INTO `table_1` VALUES (2000, ...); +INSERT INTO `table_1` VALUES (3000, ...); +``` + + +Good: + +```SQL +INSERT INTO `table_1` VALUES +(1000, ...), +(2000, ...), +(3000, ...); +``` + +### UPDATE + +Bad: + +```SQL +UPDATE `table_1` SET `field_1` = 'someValue' WHERE `entry` = 1000; +UPDATE `table_1` SET `field_1` = 'someValue' WHERE `entry` = 2000; +UPDATE `table_1` SET `field_1` = 'someValue' WHERE `entry` = 3000; +``` + +Good: + +```SQL +UPDATE `table_1` SET `field_1` = 'someValue' WHERE `entry` IN (1000, 2000, 3000); +``` + +### DELETE + +Bad: + +```SQL +DELETE FROM `table_1` WHERE `entry` = 1000; +DELETE FROM `table_1` WHERE `entry` = 2000; +DELETE FROM `table_1` WHERE `entry` = 3000; +``` + +Good: + +```SQL +DELETE FROM `table_1` WHERE `entry` IN (1000, 2000, 3000); +``` + ## How to create an sql update file This kind of procedure is pretty simple and allow any kind of dev, but also testers, to avoid multiple import of the same queries. @@ -32,4 +90,4 @@ This feature grants you ( dev / tester / user ) to: - create PR without going crazy with the alter table header, but avoiding multiple imports - avoid wrong order of updates -- avoid data inconsistency if an sql generates an error
\ No newline at end of file +- avoid data inconsistency if an sql generates an error |
