By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE `Phonebook` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int NOT NULL,
`first_name` varchar(250) NOT NULL,
`mobile` varchar(250) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`user_id`, `first_name`, `mobile`)
) ENGINE=InnoDB AUTO_INCREMENT=3520 DEFAULT CHARSET=latin1
INSERT INTO `Phonebook`
(`user_id`, `first_name`, `mobile`)
VALUES(4,'tom','+919810012345');
SELECT * FROM `Phonebook`
id | user_id | first_name | mobile |
---|---|---|---|
3520 | 4 | tom | +919810012345 |
INSERT INTO `Phonebook`
(`user_id`, `first_name`, `mobile`)
VALUES(4,'tom','+919810012345')
ON DUPLICATE KEY UPDATE user_id = user_id;
SELECT * FROM `Phonebook`
id | user_id | first_name | mobile |
---|---|---|---|
3520 | 4 | tom | +919810012345 |