Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int value with positive only entry

Tags:

oracle

I'm trying to create a table and I can only have positive values for an INT, how would I do that?

CREATE TABLE Ingredients(
IngredientID    INTEGER     PRIMARY KEY     NOT NULL,
IngredientName  VARCHAR(255),
IngredientClassID   SMALLINT    NOT NULL,
MeasureAmountID      SMALLINT    NOT NULL
);
like image 421
user2923395 Avatar asked Nov 28 '13 05:11

user2923395


People also ask

How do you make input only accept positive numbers?

You can force the input to contain only positive integer by adding onkeypress within the input tag. Here, event. charCode >= 48 ensures that only numbers greater than or equal to 0 are returned, while the min tag ensures that you can come to a minimum of 1 by scrolling within the input bar.

What are positive integer values?

An integer is positive if it is greater than zero, and negative if it is less than zero. Zero is defined as neither negative nor positive.

How do I get only positive input in python?

The abs() function is used to get the absolute (positive) value of a given number. The argument may be an integer or a floating point number.


2 Answers

try this...

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

);
like image 184
KethanKumar Avatar answered Oct 08 '22 05:10

KethanKumar


You can create a Check constraint for each column to accept only positive values.

CREATE TABLE Ingredients(
IngredientID    INTEGER PRIMARY KEY constraint IngredientID_Positive
check (IngredientID >= 0),
IngredientName  VARCHAR(255),
IngredientClassID   SMALLINT    NOT NULL,
MeasureAmountID      SMALLINT    NOT NULL
);
like image 27
Vishwanath Dalvi Avatar answered Oct 08 '22 05:10

Vishwanath Dalvi