本文介绍了是否可以为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
这篇关于是否可以为SQL Server 2008 r2中的列设置最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!