Serial

Last updated on
11 February 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Serial is a self-incrementing Integer data type. A Serial key must be indexed and the index is usually the Primary key.

Sample Code:

$field['fieldname'] = array(
  'type' => 'serial', 
  'unsigned' => TRUE, 
  'size' => 'small', // tiny / small / medium / normal / big
  'not null' => TRUE, 
  'description' => t('Field fieldname for tablename.'),
);

MySQL field mappings in the schema.inc file:

'serial:tiny'     => 'TINYINT',
'serial:small'    => 'SMALLINT',
'serial:medium'   => 'MEDIUMINT',
'serial:big'      => 'BIGINT',
'serial:normal'   => 'INT',
Storage requirements and Maximum Values:
Type         Storage            Minimum Value        Maximum Value  
             (Bytes)          (Signed/Unsigned)    (Signed/Unsigned)

TINY: SIGNED     1                   -128                  127

TINY: UNSIGNED                          0                  255


SMALL:SIGNED     2                 -32768                32767

SMALL: UNSIGNED                         0                65535


MEDIUM: SIGNED   3               -8388608               8388607

MEDIUM: UNSIGNED                        0              16777215


NORMAL: SIGNED   4            -2147483648            2147483647

NORMAL: UNSIGNED                        0            4294967295


BIG: SIGNED       8  -9223372036854775808   9223372036854775807

BIG: UNSIGNED                           0  18446744073709551615

Help improve this page

Page status: No known problems

You can: