vendredi 9 octobre 2015

change distinct rows if exists or insert or remove

I have table:

CREATE TABLE tbl_teams (            
    id integer  primary key, 
    team_id varchar(80), 
    team_title varchar(80), 
    team_city varchar(80)
)

from server comes some list of active teams, for example in JSON-format:

{
    "teams":[
    {
            "team_id":678,
            "title":"Red Heads",
            "town":"Moscow"
    },
    {
            "team_id":90,
            "title":"Blue Hands",
            "town":"Baghdad"
    },
    {
            "team_id":128,
            "title":"White Tails",
            "town":"Paris"
    }
    ]} 

How set table tbl_teamsto actual state? I mean, title and town can be changed, constant only team_id. Teams can be changed, or inserted if team_id not exists in table, or removed if not exists in server response.

Hope for help.

Aucun commentaire:

Enregistrer un commentaire