c# - MySQL insert if not exists/ignore -


so here's table layout:

type_of     agreement ipad        heyo! i'm agreement! ipod touch  i'm agreement! 

basically, i'm building admin interface administrator can add new types. i'd make he/she can't enter new type exists. basically, in above example, if enter 'ipad' in new type box , press submit, ignored or error thrown or something.

here's existing mysql statement:

insert ignore agreements (type_of, agreement) values (?, ?) com.parameters.addwithvalue("", request.form["pies"]); com.parameters.addwithvalue("", "wahey! sample license!"); 

(upgrading answer)

you need define unique index on type_of. explained in the manual:

a unique index creates constraint such values in index must distinct. error occurs if try add new row key value matches existing row. engines, unique index permits multiple null values columns can contain null. if specify prefix value column in unique index, column values must unique within prefix.

therefore:

alter table agreements add unique index (type_of); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -