插入的时候判断是否存在

-- insert into 表(字段) select 值 where not exists(select id from 表 where 验证重复的约束字段)
insert into [t_direct_airline_limit]
(
    plat
    ,shop
    ,dep
    
    ,arr
    ,valid
)
select
9,1,'CTU','PEK','Y'
where 
not exists(
    select 
    t.id 
    from [t_direct_airline_limit] t 
    with(nolock,index=_i_plat_shop,index=_i_dep,index=_i_arr) 
    where (1=1) 
    and t.plat=9 
    and t.shop=1 
    and t.dep='CTU' 
    and t.arr='PEK'
)

 

posted @ 2018-09-28 10:12  稚语希听  阅读(180)  评论(0)    收藏  举报