id作为自增int SQL语句如下即可:
上一条
月度归档: 2011年8月
MySQL replace into 用法(insert into 的增强版)
在向表中插入数据的时候,经常遇到这样的情况:1. 首先判断数据是否存在; 2. 如果不存在,则插入;3.如果存在,则更新。
在 SQL Server 中可以这样处理:
if not exists (select 1 from t where id = 1) insert into t(id, update_time) values(1, getdate()) else update t set update_time = getdate() where id = 1