に適用され、項目の3種類があります。SQLのチェック制約は、だから私は、私はアイテムを追跡し、このテーブルを持っているすべての行
- は武器
- アーマー
- ポーション
- CK_Weapon:
私はそれらのための3つのチェック制約を作成しました
- CK_Armour:
CHECK ([Type]=(2) AND NOT ([PhysReduction]+[ElemReduction]<(1)))
- CK_Potion:
([Type]=(3) AND ([PhysDamage]+[ElemDamage])=(0) AND [AttackSpeed]=(0) AND ([PhysReduction]+[ElemReduction])=(0));
私は次のインサートとポーションを追加しよう。
DECLARE @num int, @Type int, @Name varchar(50), @Description varchar(50), @Gold int
SET @Type = 3
SET @Name = 'Spirit Potion'
SET @Description = 'Restores a bit of Spirit'
SET @Gold = 150
insert into Item(Type, Name, Description, GoldValue) VALUES(@Type, @Name, @Description, @Gold)
私は次のエラーを取得:
The INSERT statement conflicted with the CHECK constraint "CK_Weapon". The conflict occurred in database "Database", table "dbo.Item".
をしかし、ポーションタイプが3でなければなりませんので、それは、すべてでこのチェックをトリガーするべきではありません!
これらのCHECKを簡単に変更できるので、タイプが同じ場合にのみトリガーされます。
insert文を追加して質問を編集します。 –