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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -