views:

31

answers:

1

I had a table with unique Date_t1 date type field, but in Table description field is not mentioned as unique, now while inserting new row i need to validate if date exist or not, If already exist i should not allow to make changes on that row, neither a new row needs to be created, Any idea how to resolve this problem in efficient way,

+1  A: 

Since you're using a UNIQUE index.. you can use this to your advantage with INSERT IGNORE

Consider the following:

INSERT IGNORE INTO your_table SET id = 100 ...

Assuming id is the UNIQUE column here... MySQL will throw an error if you try to re-insert this. But since you're using IGNORE, the error is silently thrown away.

Matt