mysql - Create a trigger or a constraint to filer duplicate data -
how create trigger or constraint filter duplicate data going input database afterward. duplicate means both sensor_id , time same.
for example, table is
rain_gage sensor_id time 2.434 6000 2017-07-24 14:23:55 5.324 6010 2017-07-24 09:12:22
now insert new data table through spring boot's repository.
rain_gage sensor_id time 2.434 6000 2017-07-24 14:23:55 5.324 6010 2017-07-24 10:23:19
i want trigger or constraint filter row (2.434, 6000, 2017-07-24 14:23:55).
then table
rain_gage sensor_id time 2.434 6000 2017-07-24 14:23:55 5.324 6010 2017-07-24 09:12:22 5.324 6010 2017-07-24 10:23:19
btw, use mysql database.
if table created, needs altered add unique
constraint on required fields.
alter table <table-name> add constraint <constraint-name> unique (sensor_id, time);
the unique
constraint can added @ time of table creation.
create table <table-name> ( .... constraint <constraint-name> unique (sensor_id, time) );
this ensure unique records inserted. exceptions occur duplicate records have handled gracefully.
Comments
Post a Comment