INTEGER
Example
Section titled “Example”CREATE TABLE Employee_Addresses ( ID INTEGER PRIMARY KEY, Street VARCHAR(255), City VARCHAR(255));
INSERT INTO Employee_Addresses (ID, Street, City)VALUES (12345, '123 Maple Ave', 'New York');
SELECT * FROM Employee_Addresses;Output
Section titled “Output”+-------+---------------+-----------+| ID | Street | City |+-------+---------------+-----------+| 12345 | 123 Maple Ave | New York |+-------+---------------+-----------+Explanation
Section titled “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
Section titled “Example”CREATE TABLE Employees ( ID INTEGER, Name TEXT);INSERT INTO Employees (ID, Name) VALUES (1, 'John Doe');SELECT * FROM Employees;Output
Section titled “Output” ID | Name----+---------- 1 | John DoeExplanation
Section titled “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
Section titled “Example”CREATE TABLE Employees ( ID INT, Name NVARCHAR(100));
INSERT INTO Employees (ID, Name)VALUES (1, 'John Doe');Output
Section titled “Output”TABLE Employees:ID | Name----------------1 | John DoeExplanation
Section titled “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
Section titled “Example”CREATE TABLE employees ( emp_id INTEGER PRIMARY KEY, name VARCHAR2(100), age INTEGER);
INSERT INTO employees(emp_id, name, age)VALUES (101, 'John Doe', 30);
SELECT * FROM employees;Output
Section titled “Output”EMP_ID NAME AGE----------------------101 John Doe 30Explanation
Section titled “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
Section titled “Example”CREATE TABLE Students ( ID INTEGER, Name TEXT);
INSERT INTO Students (ID, Name)VALUES (1, 'Alice'), (2, 'Bob');
SELECT * FROM Students;Output
Section titled “Output”ID Name1 Alice2 BobExplanation
Section titled “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.