UNSIGNED
UNSIGNED is an attribute used in SQL databases to ensure that a particular column can only hold positive integers and zero. It's typically applied to numeric data types, effectively increasing the maximum value that can be stored while disallowing negative values.
Example
Output
Explanation
The id
column is created as an INT UNSIGNED
. This means that the id
column can hold any integer between 0 and 4294967295.
Example
Output
Explanation
The SQL Server does not have ‘UNSIGNED’ integer data type. If we try to create a table using ‘UNSIGNED’ integer data type, we’ll receive an error: Column ‘ID’ in table ‘Test’ cannot be of a type that is invalid for use as a key column in an index.
Example
Output
Explanation
In Oracle, there is no direct UNSIGNED attribute for numeric data types, which ensures a non-negative value. Instead, a check constraint is used to enforce non-negative values. In the given example, the age column has a check constraint. Upon trying to insert a negative value for age, Oracle throws a check constraint violation error.