是否可以为SQL Server 2008 r2中的列设置最大值

是否可以为SQL Server 2008 r2中的列设置最大值

问题描述:

我的问题很简单,但我不确定是否可能.

My question is pretty simple but I'm not sure if it's possible.

假设我有一个表格,它包含下面的列

Assume I have a table and it contains the column below

PokemonHappiness    smallint

是否可以为该列设置最大值?

Is it possible to set a maximum value for that column?

例如,如果我将最大值设置为10000并发送这样的查询

For instance if I set the maximum to 10000 and send a query like this

--Assume that PokemonHappiness is equal to 9990
update mytable set PokemonHappiness = PokemonHappiness+50   

它应该变成10000,而不是10040

it should become 10000 instead of 10040

这可能吗?

触发器.我测试了这个.

A trigger. I tested this.

CREATE TRIGGER dbo.Table_2update
ON dbo.Table_2
FOR INSERT, UPDATE 
AS BEGIN
  UPDATE dbo.Table_2 SET dbo.Table_2.memberID = 10000
  FROM INSERTED
  WHERE inserted.id = Table_2.id 
    AND dbo.Table_2.memberID > 10000
END