php - How to prevent duplicate records from insert to my table? -
this question has answer here:
- mysql - make existing field unique 7 answers
+-----+--------------+--------+-----------+ | 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 table structure, can see id=1 , id=2
have same data. how prevent same data insert table?
add unique constraint/index:
create unique index idx_table_3 on table(a_no, status, req_date);
this prevent duplicates in table. attempt insert duplicates result in error.
Comments
Post a Comment