Repository: tobymao/sqlglot

Issue:
MySQL auto_increment to T-SQL transpile
When try to transpile DDL statement contains `auto_increment` from MySQL to T-SQL I get not supported query
```
import sqlglot
sql = '''
create table tbl (id int auto_increment primary key, name varchar(20), city varchar(20), salary int);
'''
sqlglot.transpile(sql, read="mysql", write="tsql", pretty=False)[0]
```

> CREATE TABLE tbl (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20), city VARCHAR(20), salary INTEGER)


Transpiling same query to postgres works good, returning 
```
import sqlglot
sql = '''
create table tbl (id int auto_increment primary key, name varchar(20), city varchar(20), salary int);
'''
sqlglot.transpile(sql, read="mysql", write="postgres", pretty=False)[0]
```

> CREATE TABLE tbl (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY, name VARCHAR(20), city VARCHAR(20), salary INT)

The issue can be fixed by transpile MySQL `AUTO_INCREMENT` statement  to `IDENTITY(1,1)` in TSQL


Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/tsql.py b/sqlglot/dialects/tsql.py
--- a/sqlglot/dialects/tsql.py
+++ b/sqlglot/dialects/tsql.py
@@ -631,6 +631,7 @@ class Generator(generator.Generator):
         TRANSFORMS = {
             **generator.Generator.TRANSFORMS,
             exp.AnyValue: any_value_to_max_sql,
+            exp.AutoIncrementColumnConstraint: lambda *_: "IDENTITY",
             exp.DateAdd: generate_date_delta_with_unit_sql,
             exp.DateDiff: generate_date_delta_with_unit_sql,
             exp.CurrentDate: rename_func("GETDATE"),
@@ -763,3 +764,11 @@ def constraint_sql(self, expression: exp.Constraint) -> str:
             this = self.sql(expression, "this")
             expressions = self.expressions(expression, flat=True, sep=" ")
             return f"CONSTRAINT {this} {expressions}"
+
+        # https://learn.microsoft.com/en-us/answers/questions/448821/create-table-in-sql-server
+        def generatedasidentitycolumnconstraint_sql(
+            self, expression: exp.GeneratedAsIdentityColumnConstraint
+        ) -> str:
+            start = self.sql(expression, "start") or "1"
+            increment = self.sql(expression, "increment") or "1"
+            return f"IDENTITY({start}, {increment})"


Test patch:
diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -443,6 +443,20 @@ def test_types_bin(self):
         )
 
     def test_ddl(self):
+        self.validate_all(
+            "CREATE TABLE tbl (id INTEGER IDENTITY PRIMARY KEY)",
+            read={
+                "mysql": "CREATE TABLE tbl (id INT AUTO_INCREMENT PRIMARY KEY)",
+                "tsql": "CREATE TABLE tbl (id INTEGER IDENTITY PRIMARY KEY)",
+            },
+        )
+        self.validate_all(
+            "CREATE TABLE tbl (id INTEGER NOT NULL IDENTITY(10, 1) PRIMARY KEY)",
+            read={
+                "postgres": "CREATE TABLE tbl (id INT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 10) PRIMARY KEY)",
+                "tsql": "CREATE TABLE tbl (id INTEGER NOT NULL IDENTITY(10, 1) PRIMARY KEY)",
+            },
+        )
         self.validate_all(
             "IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = object_id('db.tbl') AND name = 'idx') EXEC('CREATE INDEX idx ON db.tbl')",
             read={