INT2

INT2 is a small integer data representation in SQL. It uses 2 bytes of storage and can store numbers in the range from -32,768 to 32,767.

Example

CREATE TABLE test_table (
id INT PRIMARY KEY,
small_number INT2
);
INSERT INTO test_table VALUES (1, 10);
SELECT * FROM test_table;

Output

id | small_number
----+-------------
1 | 10

Explanation

In this example, a table named test_table is created with two columns: id and small_number. The data type of id is INT (Integer), while small_number is INT2. An insertion is then performed into test_table where id is 1 and small_number is 10. The SELECT statement retrieves and displays the data from the table, as indicated in the output.

In PostgreSQL, INT2 is used for storing small integers, with a size of two bytes and a range of -32768 to +32767.

Example

CREATE TABLE Student (
ID INT2,
Name TEXT
);
INSERT INTO Student (ID, Name) VALUES (1, 'John Doe');

Output

sqlite> SELECT * FROM Student;
1|John Doe

Explanation

The INT2 data type is used to store small integer values in SQLite. In the above code, a new table Student is created with ID as INT2 and Name as TEXT. After that, a row is inserted into Student using the INSERT statement. When querying the data with SELECT, it displays the inserted row.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.