Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 39 ยท Tables and Data Model

Tables and Records

Learn how ServiceNow stores data: tables, columns, records, sys_id, system fields, naming rules, how to create a custom table and how to inspect any table.

Every list, form, report and script in ServiceNow sits on top of tables. If you understand tables you understand the platform's data model. This lesson covers the basics: what a table is, the fields every table gets for free, naming conventions and how to create a table of your own.

Tables, columns and records

A table holds one kind of thing. A column (also called a field) is one attribute. A record is one row. The table incident has columns like number, caller_id, state and short_description, and each incident is a row.

Technically each table has two names:

  • Label: the friendly name users see ("Incident").
  • Name: the database name used in scripts and URLs (incident).

Each column has the same pair: a Column label ("Short description") and a Column name (short_description). Scripts always use the name.

System columns

Every table automatically has:

Column Purpose
sys_id 32-character unique id of the record
sys_created_on, sys_created_by When and who created it
sys_updated_on, sys_updated_by Last change
sys_mod_count Number of times it was updated
sys_class_name Which table in an extension hierarchy the record really belongs to

The sys_id is the reliable key. Display names such as a user's name may change or repeat, but the sys_id does not.

Python A table as rows and sys_ids (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Table naming rules

  • Out-of-the-box tables use a short name: incident, problem, sys_user. Names starting with sys_ are system tables.
  • Custom tables in the global scope start with u_ (for example u_vendor_contract).
  • Tables in a scoped application start with the scope name: x_acme_laptops_request.
  • Names are lowercase with underscores and have practical length limits, so keep them short.

Why prefixes? They prevent collisions with future ServiceNow tables and make it obvious what you created.

Creating a table

  1. Open System Definition > Tables and press New.
  2. Set Label (for example "Vendor Contract"); the Name is generated with the prefix.
  3. Choose Extends table if you want to inherit columns (the next lessons explain this). Leave it empty for a standalone table.
  4. Leave Auto-number checked if you want a number column such as VC0001001, and tick Create module and Create access controls if you want a navigator entry and default ACLs.
  5. In the Columns related list add fields: name, type, max length, mandatory, default value.
  6. Submit.

You can then open u_vendor_contract.list and create records right away.

Creating or changing tables in production without a plan is risky. Table and column changes are captured in update sets, but deleting a column deletes its data. Test in a development instance first.

Inspecting any table

Three ways to see what a table contains:

  1. System Definition > Tables, open the table, read the Columns list.
  2. Schema map (see Dictionary and Schema Tools).
  3. On a form or list, Configure > Table (right-click the header), then Columns.

On a list, Personalize list columns (gear icon) shows which columns are displayed. Many columns exist that you never see on a form, so look at the table definition rather than only at the form.

Python Naming checker for custom tables (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Records: create, read, update, delete

Using the UI you:

  • Create: New on a list, or a table.do form. Fill the fields, Submit.
  • Read: open from a list, or filter.
  • Update: change fields and Save / Update.
  • Delete: Delete button, or right-click a list row, subject to ACLs.

Developers do the same through scripts and REST APIs (covered in later chapters). Behind the scenes it is always insert, query, update and delete on a table, plus the rules that run around those operations.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Which value should a script use to refer to a column?

    Scripts and queries use the backend column name, such as short_description.
  2. 2. What prefix does a custom table in the global scope get?

    Global custom tables use u_; scoped tables use the application scope prefix.
  3. 3. Why is sys_id the safest record key?

    The sys_id is a unique 32-character id; names and numbers can change or repeat.

Summary

  • Tables hold records; columns hold attributes; every record has a sys_id.
  • Use column names in scripts, labels in the UI.
  • Custom tables use u_ or the scope prefix.
  • Create tables in System Definition > Tables and review columns there.

Next: Field Types