1. Home
  2. Computer Science MCQs
  3. MySQL
  4. How can you prevent duplicate entries in a MySQL table?

Added 27 Jan 2024

How can you prevent duplicate entries in a MySQL table?

  1. Use the UNIQUE constraint on a column.  Correct answer
  2. Set the primary key to auto-increment.
  3. Use the NOT NULL constraint on all columns.
  4. Manually check for duplicates before inserting data.

Correct answer

A. Use the UNIQUE constraint on a column. 

18 views

MCQSEXAM

Explanation

Use the UNIQUE constraint on the column. MySQL will then reject any INSERT or UPDATE that would create a repeated value, enforcing the rule at database level.

An auto-increment primary key only makes the ID unique, NOT NULL only blocks empty values, and manual checking is slow and unreliable when several users write at once.

Want more practice? Try the full set of Database Management Systems MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More MySQL MCQs

Practise all MySQL MCQs

Similar MCQs