what is the primary key of a table?

jerryt
Tera Contributor

Hi there,

I'm using Helsinki and I'm wondering what is the primary key in a table.

It looks that most of the tables have a column 'sys_id', which seems like the primary key in that table. When I navigate to 'Tables and Columns', I see a big blue circle icon with an 'i' inside beside sys_id: pk.PNG

But some tables don't have sys_id. For example, pa_favorites and v_db_index seem not to have primary keys.

There's another interesting table. ts_word_roots has 3 columns and they are like this:

ts_word_roots.PNG

So my questions are:

1. How can I check what is the primary key in a table? (usually sys_id I guess, but I'm not sure)

2. Are there any tables without primary keys? (like pa_favorites and v_db_index?)

3. For table ts_word_roots, does it have a composite primary key?

Thanks a lot!

1 ACCEPTED SOLUTION

Hi Jerry,



Yes, where there is a sys_id, that's the primary key. I checked some of the others you mentioned and here's what I found.


  • pa_favorites - PRI=user
  • v_db_index - PRI=sys_id
  • ts_word_roots - PRI=index,raw_word,stemmed_word


Let me know if there are any other specifics you need.


View solution in original post

11 REPLIES 11

Chuck Tomasi
Tera Patron

Hi Jerry,



The "I" icon represents the field is indexed.



You are correct, in most cases, sys_id is the primary key. Where there is no primary key, I don't know, but I'll check. Interesting question.



Why the interest in database details?


Thanks Chuck, our team is making an ODBC driver which uses ServiceNow as data source, so we need to know some database details.


So if a table has sys_id as a column, then we can consider sys_id as the primary key, is that always the case?


I haven't done any changes to the tables in my sandbox yet, so by default sys_id is the primary key?


Hi Jerry,



Yes, where there is a sys_id, that's the primary key. I checked some of the others you mentioned and here's what I found.


  • pa_favorites - PRI=user
  • v_db_index - PRI=sys_id
  • ts_word_roots - PRI=index,raw_word,stemmed_word


Let me know if there are any other specifics you need.


Thanks Chuck, does v_db_index has sys_id? I only see a column 'index'. Is it the primary key? Or do I need to set it as the primary key?