我正在尝试创建一个表,我只能为INT设置正值,我该怎么做?
CREATE TABLE Ingredients(
IngredientID INTEGER PRIMARY KEY NOT NULL,
IngredientName VARCHAR(255),
IngredientClassID SMALLINT NOT NULL,
MeasureAmountID SMALLINT NOT NULL
);
答案 0 :(得分:9)
试试这个......
CREATE TABLE Ingredients(
IngredientID INTEGER PRIMARY KEY,
IngredientName VARCHAR(255),
IngredientClassID SMALLINT NOT NULL,
MeasureAmountID SMALLINT NOT NULL,
CHECK (IngredientClassID>0),
CHECK (MeasureAmountID>0)
);
答案 1 :(得分:1)
您可以为每列创建Check constraint以仅接受正值。
CREATE TABLE Ingredients(
IngredientID INTEGER PRIMARY KEY constraint IngredientID_Positive
check (IngredientID >= 0),
IngredientName VARCHAR(255),
IngredientClassID SMALLINT NOT NULL,
MeasureAmountID SMALLINT NOT NULL
);