表结构如下:
Table test
varchar id, /*id 号*/
int maxSize, /*容量的最大限制*/
int content; /*容量*/如果我想增大容量,但是不能超过最大限制。我可以这样做,
select content,maxSize from test where id='?' 然后进行判断
if content+一个数 > maxSize()
不能增加;
else
{
update test set content=content+一个数 where id='?'
} 但是我觉得这样太麻烦了,要去查两遍数据库,有没有好的办法?谢谢了
(id varchar(1),
maxSize int,
content int
)insert into test1(id,maxSize,content) select '1',20,19update test1 set content=content+1 where id='1' and content+1<=maxSize