我正在嘗試創建一個表,並且我只能對INT具有正值,我該怎麼做?INT值只有正值條目
CREATE TABLE Ingredients(
IngredientID INTEGER PRIMARY KEY NOT NULL,
IngredientName VARCHAR(255),
IngredientClassID SMALLINT NOT NULL,
MeasureAmountID SMALLINT NOT NULL
);
我正在嘗試創建一個表,並且我只能對INT具有正值,我該怎麼做?INT值只有正值條目
CREATE TABLE Ingredients(
IngredientID INTEGER PRIMARY KEY NOT NULL,
IngredientName VARCHAR(255),
IngredientClassID SMALLINT NOT NULL,
MeasureAmountID SMALLINT NOT NULL
);
試試這個...上_column_
CREATE TABLE Ingredients(
IngredientID INTEGER PRIMARY KEY,
IngredientName VARCHAR(255),
IngredientClassID SMALLINT NOT NULL,
MeasureAmountID SMALLINT NOT NULL,
CHECK (IngredientClassID>0),
CHECK (MeasureAmountID>0)
);
工作過,謝謝! – user2923395
接受答案,如果你覺得有用..謝謝 – KethanKumar
您可以爲每列創建一個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
);
積極進入? –