mysql multiple unique values per primary key I have a table that stores multiple phone numbers. While the same number can exist in the table I want to ensure that a user can't have the same number twice.

**Valid**

id0001 : 5555550000
id0001 : 5555550001
id0002 : 5555550000

**Invalid**

id0001 : 5555550000
id0001 : 5555550000
id0002 : 5555550001


Not sure the best approach.  Should I make a function and apply it as a constraint?

Should I change the structure of the table?

CREATE TABLE `callback` (
    `f_unti_id` INT(10) NOT NULL,
    `phone_number` varchar(10) NOT NULL
);

ALTER TABLE `callback` ADD CONSTRAINT `callback_fk0` FOREIGN KEY (`f_unti_id`) REFERENCES `unit`(`unit_id`);
You just need a composite (a.k.a. compound or multi-column) PRIMARY KEY:

CREATE TABLE callback
(
    f_unti_id varchar(10) NOT NULL,
    phone_number varchar(10) NOT NULL,

    -- Compound PK
    PRIMARY KEY(f_unti_id, phone_number)
);


(Actually, a UNIQUE constraint on multiple columns would suffice. Check How do I specify unique constraint for multiple columns in MySQL?).

Try it a http://sqlfiddle.com/#!9/9882a/1/0