[MDEV-14873] ALTER TABLE DROP CONSTRAINT does not work for unique constraints Created: 2018-01-05  Updated: 2020-07-17  Resolved: 2020-07-17

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 10.2.12
Fix Version/s: 10.2.33

Type: Bug Priority: Major
Reporter: Lukas Eder Assignee: Rucha Deodhar
Resolution: Done Votes: 1
Labels: None

Issue Links:
Relates
relates to MDEV-10038 ALTER TABLE DROP CONSTRAINT not worki... Closed

 Description   

The syntax is supported in MariaDB 10.2.1 (https://mariadb.com/kb/en/library/alter-table/#drop-constraint), but it doesn't work for unique constraints:

create table t (
  a int,
  b int,
  
  constraint x unique (a),
  constraint y check (b = 1)
);
 
-- Does not work:
alter table t drop constraint x;
 
-- These work:
alter table t drop key x;
alter table t drop constraint y;

Note, this looks like a duplicate of MDEV-10038, but at the time of MDEV-10038, the syntax wasn't yet supported by MariaDB. Now it is. Feel free to close this as a duplicate of the other (and reopen the other), if you think that's the better approach.



 Comments   
Comment by Elena Stepanova [ 2018-01-07 ]

As discussed, alter table t drop constraint x should work for a unique key x.

Comment by Rucha Deodhar [ 2020-07-17 ]

Works on 10.2:

MariaDB [test]> create table t (
    ->   a int,
    ->   b int,
    ->   
    ->   constraint x unique (a),
    ->   constraint y check (b = 1)
    -> );
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> INSERT INTO t VALUES(1,1);
Query OK, 1 row affected (0.00 sec)
 
MariaDB [test]> INSERT INTO t VALUES(1,2);
ERROR 4025 (23000): CONSTRAINT `y` failed for `test`.`t`
MariaDB [test]> INSERT INTO t VALUES(2,1);
Query OK, 1 row affected (0.00 sec)
 
MariaDB [test]> INSERT INTO t VALUES(2,1);
ERROR 1062 (23000): Duplicate entry '2' for key 'x'
MariaDB [test]> ALTER TABLE t DROP CONSTRAINT x;
Query OK, 2 rows affected (0.01 sec)               
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> INSERT INTO t VALUES(2,1);
Query OK, 1 row affected (0.00 sec)
 
MariaDB [test]> SELECT * FROM t;
+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
|    2 |    1 |
|    2 |    1 |
+------+------+
3 rows in set (0.00 sec)

Comment by Rucha Deodhar [ 2020-07-17 ]

Looks like this is already fixed.

Generated at Thu Feb 08 08:16:56 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.