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 multiplenull
values columns can containnull
. if specify prefix value column inunique
index, column values must unique within prefix.
therefore:
alter table agreements add unique index (type_of);
Comments
Post a Comment