0

When should serial be chosen over an int when choosing a data type for a table column? Are they separated out for indicating a difference in the data types. If so what type of data should be stored as serial and as int?

Examples would be greatly appreciated.

  • Serial is used for auto-increment column of the table, e.g. for node table nid has a serial data type and int can be any number based on size provided. – Vishal Patil Dec 11 '17 at 12:06
  • Thanks, I was wondering if that was the case. So the auto increment is implicit? Is there any documentation I can look at in regards to this. From the searching I was doing I couldn't find any. – Lsakurifaisu Dec 11 '17 at 12:32
0

Serial is used for auto-increment column of the table(so here auto increment is implicit), e.g. for node table nid has a serial data type and int can be any number based on size provided.

'type': The generic datatype: 'varchar', 'char', 'int', 'serial', 'float', 'numeric', 'text', 'blob' or 'datetime'. The types map to the underlying database engine specific datatypes. Use 'serial' for auto incrementing fields.

Reference: https://www.drupal.org/docs/7/api/schema-api/schema-reference

  • Great, thank you for creating an answer for this. Much appreciated! – Lsakurifaisu Dec 11 '17 at 14:45
  • Is it required to use the serial type if we have an integer field that is the primary key? For example, I'm creating a custom table that will be indexed by the node ID, but with existing node ID's, not any new ones I create. – Kimberly W Jul 8 '18 at 17:55
  • Its not required. – Vishal Patil Jul 9 '18 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.