1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| CREATE TABLE user_contacts ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, contact_type VARCHAR(20), contact_value VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_user_contact (user_id, contact_type) );
INSERT IGNORE INTO user_contacts (user_id, contact_type, contact_value) VALUES (1, 'email', 'user1@example.com'), (1, 'phone', '13800138000'), (1, 'email', 'new_email@example.com');
INSERT INTO user_contacts (user_id, contact_type, contact_value) VALUES (1, 'email', 'updated_email@example.com'), (2, 'phone', '13900139000') ON DUPLICATE KEY UPDATE contact_value = VALUES(contact_value);
|