First We have created Table:
CREATE TABLE IF NOT EXISTS `userlist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Listname` varchar(50) NOT NULL,
`Listval1` varchar(50) NOT NULL,
`Listval2` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Next Execute this query:
ALTER TABLE `userlist` ADD UNIQUE KEY (Listname,Listval1);
Insert Rows:
INSERT INTO `tiketsoft`.`userlist` (`id`, `Listname`, `Listval1`, `Listval2`) VALUES (NULL, 'country', 'India', 'IN');
same record insert again its display below message
#1062 - Duplicate entry 'country-India' for key 'Listname'
Same time execute below query run successfully:
INSERT INTO `tiketsoft`.`userlist` (`id`, `Listname`, `Listval1`, `Listval2`) VALUES (NULL, 'country', 'China', 'Ch');
CREATE TABLE IF NOT EXISTS `userlist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Listname` varchar(50) NOT NULL,
`Listval1` varchar(50) NOT NULL,
`Listval2` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Next Execute this query:
ALTER TABLE `userlist` ADD UNIQUE KEY (Listname,Listval1);
Insert Rows:
INSERT INTO `tiketsoft`.`userlist` (`id`, `Listname`, `Listval1`, `Listval2`) VALUES (NULL, 'country', 'India', 'IN');
same record insert again its display below message
#1062 - Duplicate entry 'country-India' for key 'Listname'
Same time execute below query run successfully:
INSERT INTO `tiketsoft`.`userlist` (`id`, `Listname`, `Listval1`, `Listval2`) VALUES (NULL, 'country', 'China', 'Ch');
No comments:
Post a Comment