php - How to prevent duplicate records from insert to my table? -


this question has answer here:

+-----+--------------+--------+-----------+ | 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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -