Define and use small int : Small Int « Data Type « SQL / MySQL






Define and use small int

   
/*
mysql> Drop table Test;
Query OK, 0 rows affected (0.11 sec)

mysql> CREATE TABLE Test
    -> (
    ->    TestID SMALLINT NOT NULL PRIMARY KEY,
    ->    Amount SMALLINT NOT NULL
    -> );
Query OK, 0 rows affected (0.05 sec)

mysql> INSERT INTO Test VALUES (101, 12),
    ->                         (102, 1),
    ->                         (103, 139),
    ->                         (104, -37),
    ->                         (105, 0),
    ->                         (106, -16);
Query OK, 6 rows affected (0.06 sec)
Records: 6  Duplicates: 0  Warnings: 0

*/

Drop table Test;

CREATE TABLE Test
(
   TestID SMALLINT NOT NULL PRIMARY KEY,
   Amount SMALLINT NOT NULL
);


INSERT INTO Test VALUES (101, 12), 
                        (102, 1), 
                        (103, 139), 
                        (104, -37), 
                        (105, 0), 
                        (106, -16);

           
         
    
    
  








Related examples in the same category

1.SMALLINT(m): 16-bit integer (2 bytes, -32,768 to + 32,767)
2.Use smallint to store year
3.CREATE TABLE statement including two column definitions, SMALLINT data type and INT data type.
4.SMALLINT data type and a default value of 1
5.SmallInt calculation
6.Compare smallint value