What Happens If Unique Value Constraints Are Violated

Q

What Happens If Unique Value Constraints Are Violated? - MySQL FAQs - Understanding SQL INSERT, UPDATE and DELETE Statements

✍: FYIcenter.com

A

If you are inserting a new record that has values violating a unique constraint, you will get an error. Note that primary key column has a unique value constraint by default. The following tutorial exercise gives you some good examples:

mysql> INSERT INTO fyi_links (url) VALUES ('www.other.com');
ERROR 1062 (23000): Duplicate entry '0' for key 1

mysql> INSERT INTO fyi_links VALUES (101, 
  'sql.fyicenter.com', 
  NULL,
  0,
  '2006-04-30');
ERROR 1062 (23000): Duplicate entry '101' for key 1

2007-05-11, 5030👍, 0💬