Repository: tobymao/sqlglot

Issue:
tsql ALTER TABLE doesn't use keyword COLUMN when adding a column 
**Fully reproducible code snippet**
```
>>> from sqlglot import transpile
>>> transpile("ALTER TABLE a ADD COLUMN b INT", write="tsql")
['ALTER TABLE a ADD COLUMN b INTEGER']
```

Expected output:
`'ALTER TABLE a ADD b INTEGER'`

Discussion:
tobymao: what about for schema?, you only changed columndef
GeorgeSittas: > what about for schema?, you only changed columndef

I think that the schema case corresponds to Spark which has the `ADD COLUMNS` syntax instead of a singular `COLUMN`. The relevant context can be found in the initial commit that introduced `ALTER TABLE ...`: https://github.com/tobymao/sqlglot/commit/f57bdd4ad

Patch:
diff --git a/sqlglot/dialects/tsql.py b/sqlglot/dialects/tsql.py
index 2f90f524..02632c0c 100644
--- a/sqlglot/dialects/tsql.py
+++ b/sqlglot/dialects/tsql.py
@@ -581,6 +581,7 @@ class TSQL(Dialect):
         QUERY_HINTS = False
         RETURNING_END = False
         NVL2_SUPPORTED = False
+        ALTER_TABLE_ADD_COLUMN_KEYWORD = False
 
         TYPE_MAPPING = {
             **generator.Generator.TYPE_MAPPING,
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index 3c6baea9..4bbb661e 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -2570,6 +2570,7 @@ class Update(Expression):
         "from": False,
         "where": False,
         "returning": False,
+        "order": False,
         "limit": False,
     }
 
diff --git a/sqlglot/generator.py b/sqlglot/generator.py
index e4427000..f3790dcd 100644
--- a/sqlglot/generator.py
+++ b/sqlglot/generator.py
@@ -186,6 +186,9 @@ class Generator:
     # SELECT * VALUES into SELECT UNION
     VALUES_AS_TABLE = True
 
+    # Whether or not the word COLUMN is included when adding a column with ALTER TABLE
+    ALTER_TABLE_ADD_COLUMN_KEYWORD = True
+
     TYPE_MAPPING = {
         exp.DataType.Type.NCHAR: "CHAR",
         exp.DataType.Type.NVARCHAR: "VARCHAR",
@@ -1354,12 +1357,13 @@ class Generator:
         from_sql = self.sql(expression, "from")
         where_sql = self.sql(expression, "where")
         returning = self.sql(expression, "returning")
+        order = self.sql(expression, "order")
         limit = self.sql(expression, "limit")
         if self.RETURNING_END:
-            expression_sql = f"{from_sql}{where_sql}{returning}{limit}"
+            expression_sql = f"{from_sql}{where_sql}{returning}"
         else:
-            expression_sql = f"{returning}{from_sql}{where_sql}{limit}"
-        sql = f"UPDATE {this} SET {set_sql}{expression_sql}"
+            expression_sql = f"{returning}{from_sql}{where_sql}"
+        sql = f"UPDATE {this} SET {set_sql}{expression_sql}{order}{limit}"
         return self.prepend_ctes(expression, sql)
 
     def values_sql(self, expression: exp.Values) -> str:
@@ -2267,7 +2271,11 @@ class Generator:
         actions = expression.args["actions"]
 
         if isinstance(actions[0], exp.ColumnDef):
-            actions = self.expressions(expression, key="actions", prefix="ADD COLUMN ")
+            actions = self.expressions(
+                expression,
+                key="actions",
+                prefix="ADD COLUMN " if self.ALTER_TABLE_ADD_COLUMN_KEYWORD else "ADD ",
+            )
         elif isinstance(actions[0], exp.Schema):
             actions = self.expressions(expression, key="actions", prefix="ADD COLUMNS ")
         elif isinstance(actions[0], exp.Delete):
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 1b699989..83c35b86 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -1936,6 +1936,7 @@ class Parser(metaclass=_Parser):
                 "from": self._parse_from(joins=True),
                 "where": self._parse_where(),
                 "returning": returning or self._parse_returning(),
+                "order": self._parse_order(),
                 "limit": self._parse_limit(),
             },
         )


Test patch:
diff --git a/tests/dialects/test_mysql.py b/tests/dialects/test_mysql.py
index 8bfb0b32..8fb3d297 100644
--- a/tests/dialects/test_mysql.py
+++ b/tests/dialects/test_mysql.py
@@ -12,6 +12,9 @@ class TestMySQL(Validator):
         self.validate_identity("CREATE TABLE foo (a BIGINT, INDEX USING BTREE (b))")
         self.validate_identity("CREATE TABLE foo (a BIGINT, FULLTEXT INDEX (b))")
         self.validate_identity("CREATE TABLE foo (a BIGINT, SPATIAL INDEX (b))")
+        self.validate_identity(
+            "UPDATE items SET items.price = 0 WHERE items.id >= 5 ORDER BY items.id LIMIT 10"
+        )
         self.validate_identity(
             "CREATE TABLE foo (a BIGINT, INDEX b USING HASH (c) COMMENT 'd' VISIBLE ENGINE_ATTRIBUTE = 'e' WITH PARSER foo)"
         )
diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index c3f9cb10..c35c7807 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -487,6 +487,12 @@ class TestTSQL(Validator):
             },
         )
 
+        self.validate_all(
+            "ALTER TABLE a ADD b INTEGER",
+            read={"": "ALTER TABLE a ADD COLUMN b INT"},
+            write={"tsql": "ALTER TABLE a ADD b INTEGER"},
+        )
+
         self.validate_all(
             "CREATE TABLE #mytemp (a INTEGER, b CHAR(2), c TIME(4), d FLOAT(24))",
             write={