Not null tinyint and AUTO_INCREMENT : AUTO_INCREMENT « Data Type « SQL / MySQL






Not null tinyint and AUTO_INCREMENT

       
mysql>
mysql> CREATE TABLE Item(
    ->     title_num TINYINT NOT NULL AUTO_INCREMENT,
    ->     title_cust CHAR(4),
    ->     PRIMARY KEY(title_num)
    -> ) ;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> DESC Item;
+------------+------------+------+-----+---------+----------------+
| Field      | Type       | Null | Key | Default | Extra          |
+------------+------------+------+-----+---------+----------------+
| title_num  | tinyint(4) | NO   | PRI | NULL    | auto_increment |
| title_cust | char(4)    | YES  |     | NULL    |                |
+------------+------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql>
mysql>
mysql> INSERT INTO Item VALUES
    -> (1, 'Mr.'),
    -> (2, 'Ms.'),
    -> (3, 'Mrs.'),
    -> (4, 'Miss'),
    -> (5, 'Sir'),
    -> (6, 'Dame'),
    -> (7, 'Dr.'),
    -> (8, 'Lady'),
    -> (9, 'None');
Query OK, 9 rows affected (0.00 sec)
Records: 9  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> drop table Item;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
    
  








Related examples in the same category

1.Using AUTO_INCREMENT
2.AUTO_INCREMENT Integers
3.Preserve column attributes such as AUTO_INCREMENT and column's default value during table copying.
4.An AUTO_INCREMENT column
5.AUTO_INCREMENT sequences start at one
6.For MyISAM tables, you can begin the sequence at a specific initial value n by including an AUTO_INCREMENT = n
7.Using an AUTO_INCREMENT Column to Create Multiple Sequences
8.AUTO_INCREMENT column:
9.MEDIUMINT NOT NULL AUTO_INCREMENT
10.INTEGER UNSIGNED AUTO_INCREMENT
11.Insert value to AUTO_INCREMENT column
12.delete and reinsert value to AUTO_INCREMENT column
13.SET @@AUTO_INCREMENT_OFFSET = 10,@@AUTO_INCREMENT_INCREMENT = 10
14.Set AUTO_INCREMENT value
15.Parameter: INT NOT NULL AUTO_INCREMENT
16.Create a similar table, preserve the auto-incrementing key
17.Defining Auto-Increment Columns
18.If this value is larger than the current sequence counter, subsequent automatically generated values begin with the value plus one