TINYINT
Example
Section titled “Example”CREATE TABLE ExampleTable ( Column1 TINYINT);
INSERT INTO ExampleTable (Column1)VALUES (5), (10), (15);
SELECT * FROM ExampleTable;Output
Section titled “Output”| Column1 |
|---|
| 5 |
| 10 |
| 15 |
Explanation
Section titled “Explanation”The TINYINT type is used in the creation of the ExampleTable, specifically for Column1. The INSERT INTO command is then used to populate Column1 with values 5, 10, and 15. The SELECT * FROM ExampleTable; command then retrieves all information from ExampleTable, displaying the inputted TINYINT values in Column1. The demonstrated records show that TINYINT can store small integer values.
Example
Section titled “Example”Here is an example of creating a table using the TINYINT data type and an insert statement to add a record to the table:
CREATE TABLE Employees( EmployeeId TINYINT PRIMARY KEY, EmployeeName NVARCHAR(100));
INSERT INTO Employees(EmployeeId, EmployeeName)VALUES (1, 'John Doe');Output
Section titled “Output”The output does not provide much visual insight as it is the backend execution of the SQL Server. However, when you try to run a select statement such as the one below:
SELECT * FROM Employees;You can expect the following output:
+------------+--------------+| EmployeeId | EmployeeName |+------------+--------------+| 1 | John Doe |+------------+--------------+Explanation
Section titled “Explanation”In the code example above, a table named Employees is created with a primary key field EmployeeId of type TINYINT, and another field EmployeeName of type NVARCHAR(100).
Then a new record is inserted into the Employees table with EmployeeId as 1 and EmployeeName as John Doe.
In SQL Server, TINYINT data type is an integer that supports values from 0 to 255.
Example
Section titled “Example”CREATE TABLE TestTable ( ID TINYINT);INSERT INTO TestTable(ID) VALUES (8);SELECT * FROM TestTable;Output
Section titled “Output”ID---8Explanation
Section titled “Explanation”In the example, a table named ‘TestTable’ is created with a single column ‘ID’ with data type as TINYINT. An integer value ‘8’ is inserted into the table and displayed by selecting all rows from the table.