2013-11-28 38 views
3

我正在嘗試創建一個表,並且我只能對INT具有正值,我該怎麼做?INT值只有正值條目

CREATE TABLE Ingredients(
IngredientID INTEGER  PRIMARY KEY  NOT NULL, 
IngredientName VARCHAR(255), 
IngredientClassID SMALLINT NOT NULL, 
MeasureAmountID  SMALLINT NOT NULL 
); 
+0

積極進入? –

回答

7

試試這個...上_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) 

); 
+1

工作過,謝謝! – user2923395

+1

接受答案,如果你覺得有用..謝謝 – KethanKumar

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 
);