-1
+-----+--------------+--------+-----------+
| id  |     a_no     | status | req_date  |
+-----+--------------+--------+-----------+
|   1 | 6019-6039120 |    0   |2015-03-01 |  
|   2 | 6019-6039120 |    0   |2015-03-01 |
|   4 | 6019-6039120 |    0   |2015-03-02 |
|   5 | 6019-6039121 |    0   |2015-03-02 |
|   6 | 6019-6039134 |    0   |2015-03-02 |
|   7 | 6019-6039134 |    0   |2015-03-02 |
|   8 | 6019-6039120 |    0   |2015-03-03 |
|   9 | 6019-6039129 |    0   |2015-03-03 |
|  10 | 6019-6039145 |    0   |2015-03-04 |
|  11 | 6019-6039167 |    0   |2015-03-04 |
+-----+--------------+--------+-----------+

This is my table structure, as you can see id=1 and id=2 have a same data. How to prevent the same data to insert into my table?

1 Answers1

4

Add a unique constraint/index:

create unique index idx_table_3 on table(a_no, status, req_date);

This will prevent duplicates in the table. An attempt to insert duplicates will result in an error.

Gordon Linoff
  • 1,122,135
  • 50
  • 484
  • 624