Repository: tobymao/sqlglot

Issue:
ALTER TABLE statement with Drop constraint not parsing properly
I was trying to parse a DROP CONSTRAINT statement in oracle and TSQL, but sqlglot.parse_one is not parsing them properly. it does not return the meta data about the drop constraint as it is giving when we add constraint. specifically i am trying it with foreign key. it works perfectly when i add constraint in alter table but does work in drop constraint

`sqlglot.parse_one(`
        `"ALTER TABLE dbo.DocExe DROP CONSTRAINT FK_Column_B;", "tsql"`
   ` )`
   
   The above example is copied from this docs https://learn.microsoft.com/en-us/sql/relational-databases/tables/delete-foreign-key-relationships?view=sql-server-ver16
   


Discussion:

Patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index ee147437..c4d3f62b 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -245,6 +245,7 @@ class Parser(metaclass=_Parser):
 
     CREATABLES = {
         TokenType.COLUMN,
+        TokenType.CONSTRAINT,
         TokenType.FUNCTION,
         TokenType.INDEX,
         TokenType.PROCEDURE,


Test patch:
diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index 5c4c3a83..59f936e9 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -561,6 +561,13 @@ class TestTSQL(Validator):
         )
 
     def test_ddl(self):
+        expression = parse_one("ALTER TABLE dbo.DocExe DROP CONSTRAINT FK_Column_B", dialect="tsql")
+        self.assertIsInstance(expression, exp.AlterTable)
+        self.assertIsInstance(expression.args["actions"][0], exp.Drop)
+        self.assertEqual(
+            expression.sql(dialect="tsql"), "ALTER TABLE dbo.DocExe DROP CONSTRAINT FK_Column_B"
+        )
+
         for clusterd_keyword in ("CLUSTERED", "NONCLUSTERED"):
             self.validate_identity(
                 'CREATE TABLE "dbo"."benchmark" ('
@@ -630,7 +637,6 @@ class TestTSQL(Validator):
                 "tsql": "CREATE OR ALTER VIEW a.b AS SELECT 1",
             },
         )
-
         self.validate_all(
             "ALTER TABLE a ADD b INTEGER, c INTEGER",
             read={
@@ -641,7 +647,6 @@ class TestTSQL(Validator):
                 "tsql": "ALTER TABLE a ADD b INTEGER, c INTEGER",
             },
         )
-
         self.validate_all(
             "CREATE TABLE #mytemp (a INTEGER, b CHAR(2), c TIME(4), d FLOAT(24))",
             write={