How can I drop the \"Unique Key Constraint\" on a column of a MySQL table using phpMyAdmin?
If you want to remove unique constraints from mysql database table, use alter table with drop index.
Example:
create table unique_constraints(unid int,activity_name varchar(100),CONSTRAINT activty_uqniue UNIQUE(activity_name),primary key (unid));
alter table unique_constraints drop index activty_uqniue;
Where activty_uqniue is UNIQUE constraint for activity_name column.
First delete table
go to SQL
Use this code:
CREATE TABLE service( --tablename
`serviceid` int(11) NOT NULL,--columns
`customerid` varchar(20) DEFAULT NULL,--columns
`dos` varchar(30) NOT NULL,--columns
`productname` varchar(150) NOT NULL,--columns
`modelnumber` bigint(12) NOT NULL,--columns
`serialnumber` bigint(20) NOT NULL,--columns
`serviceby` varchar(20) DEFAULT NULL--columns
)
--INSERT VALUES
INSERT INTO `service` (`serviceid`, `customerid`, `dos`, `productname`, `modelnumber`, `serialnumber`, `serviceby`) VALUES
(1, '1', '12/10/2018', 'mouse', 1234555, 234234324, '9999'),
(2, '09', '12/10/2018', 'vhbgj', 79746385, 18923984, '9999'),
(3, '23', '12/10/2018', 'mouse', 123455534, 11111123, '9999'),
(4, '23', '12/10/2018', 'mouse', 12345, 84848, '9999'),
(5, '546456', '12/10/2018', 'ughg', 772882, 457283, '9999'),
(6, '23', '12/10/2018', 'keyboard', 7878787878, 22222, '1'),
(7, '23', '12/10/2018', 'java', 11, 98908, '9999'),
(8, '128', '12/10/2018', 'mouse', 9912280626, 111111, '9999'),
(9, '23', '15/10/2018', 'hg', 29829354, 4564564646, '9999'),
(10, '12', '15/10/2018', '2', 5256, 888888, '9999');
--before droping table
ALTER TABLE `service`
ADD PRIMARY KEY (`serviceid`),
ADD unique`modelnumber` (`modelnumber`),
ADD unique`serialnumber` (`serialnumber`),
ADD unique`modelnumber_2` (`modelnumber`);
--after droping table
ALTER TABLE `service`
ADD PRIMARY KEY (`serviceid`),
ADD modelnumber` (`modelnumber`),
ADD serialnumber` (`serialnumber`),
ADD modelnumber_2` (`modelnumber`);
A unique constraint is also an index.
First use SHOW INDEX FROM tbl_name
to find out the name of the index. The name of the index is stored in the column called key_name
in the results of that query.
Then you can use DROP INDEX:
DROP INDEX index_name ON tbl_name
or the ALTER TABLE syntax:
ALTER TABLE tbl_name DROP INDEX index_name
You can DROP
a unique constraint from a table using phpMyAdmin as requested as shown in the table below. A unique constraint has been placed on the Wingspan field. The name of the constraint is the same as the field name, in this instance.