summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/Dealing-with-SQL-files.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/Dealing-with-SQL-files.md b/docs/Dealing-with-SQL-files.md
index b25fc18..69a97f2 100644
--- a/docs/Dealing-with-SQL-files.md
+++ b/docs/Dealing-with-SQL-files.md
@@ -58,6 +58,25 @@ Good:
UPDATE `table_1` SET `field_1` = 'someValue' WHERE `entry` IN (1000, 2000, 3000);
```
+#### Flags
+
+For flags (2^) columns, when you remove or add a flag, it is better not to override the existing value as flags are combined values.
+
+For example, given a flag with value `128`, this is how it would be to add, remove and invert it:
+
+```sql
+-- ADD AN EXTRA FLAG (|)
+UPDATE `table_1` SET `field_1` = `field_1` | 128 WHERE `entry` = 1000;
+
+-- REMOVE AN EXTRA FLAG (& ~)
+UPDATE `table_1` SET `field_1` = `field_1` & ~128 WHERE `entry` = 1000;
+
+-- INVERT A FLAG (if present = removed, if absent = added) (^)
+UPDATE `table_1` SET `field_1` = `field_1` ^ 128 WHERE `entry` = 1000;
+```
+
+This way, you will make sure that your query will only affect that specific flag, leaving all the other flags unchanged.
+
### DELETE
Bad: