INTEGER
INTEGER is a data type used in SQL databases to store whole numbers. Unlike other numeric types, it does not support decimal or fractional values. The storage size and range of values it can hold depend on the specific implementation of SQL used. In typical system, the maximum value possible for an INTEGER data type is 2147483647.
Example
Output
Explanation
The ID
column has a datatype of INTEGER
, which holds a numerical value. In this instance, the ID
for the newly created record in the Employee_Addresses
table is 12345
. This code snippet is an example of declaring a column as INTEGER
, inserting an integer value, and then querying it.
Example
Output
Explanation
In the above example, a table named ‘Employees’ is created with two columns: ‘ID’ of type INTEGER and ‘Name’ of type TEXT. A new row is inserted into the table where the ‘ID’ is 1 and the ‘Name’ is ‘John Doe’. Finally, a SELECT statement is run to retrieve all the data from the ‘Employees’ table, displaying the inserted row.
Example
Output
Explanation
In this example, an Employees table is created with two columns: ID, an integer (INT
), and Name, a variable character string (NVARCHAR
). The subsequent INSERT
statement adds a row to the table, with ‘1’ for ID and ‘John Doe’ for Name. The ID column uses the INTEGER (INT
) data type, a numeric data type that can store whole (integer) numbers.
Example
Output
Explanation
In this example, a table named ‘employees’ is created with an ‘emp_id’ as an INTEGER which is also set as the PRIMARY KEY, ‘name’ as VARCHAR2, and ‘age’ as INTEGER. One record is inserted into the ‘employees’ table and then selected to display. The ‘emp_id’ and ‘age’ fields are the demonstration of INTEGER usage.
Example
Output
Explanation
The code provided illustrates the use of the INTEGER data type. In the Students
table, it is used to define the ID
column. Two rows are then inserted into the table, with each student being given a unique ID
, demonstrating the use of INTEGER for unique numerical data. The SELECT statement is used to view all records in the table, resulting in the output provided.