You may be aware that you can store more than just text within ServiceNow, in the form of attachments. You can store binary data as well, including pictures, audio, and even executable files; but what happens when you upload a binary file as an attachment, to ServiceNow?

There are two tables which do the work of dealing with attachments: Attachments (sys_attachment), and Attachment Documents (sys_attachment_doc). When you upload an attachment file to ServiceNow, a record is created in the Attachments table with some metadata, including the file name, content type, and the size of the attached file.

The actual binary data of the file is split into ~4KB (3736 byte) chunks, which are then saved into the Data field of the Attachment Documents table. This table has a few other interesting fields, such as length (which defines the number of bytes stored in this chunk), and position (which defines what order this chunk of bytes fits in). The Attachment Documents table also contains a reference field (sys_attachment), which points to the parent record in the Attachments table.

This means that each attachment file will have one or more entries in the sys_attachment_doc table, which corresponds to the binary data of the original file that was attached. The Position field determines the order of the data in sequence, for when ServiceNow needs to re-combine the data into the original file (such as when a user wants to view or download it).