The OBJECT_ID_FROM_NODE_ID function

This function extracts the object_id from a given node_id. The following code returns the object_id for the dbo.TwitterUser node table:

SELECT OBJECT_ID_FROM_NODE_ID('{"type":"node","schema":"dbo","table":"TwitterUser","id":0}');

It parses the input string, extracts the schema and table name, and returns the object_id if all these criteria are fulfilled:

  • The input string is a JSON conforming string
  • A node table exists with the extracted table name in the extracted schema
  • The key id has a bigint value (a node_id with this value does not need to exist in the node table)

The following code will still return the correct object_id, even though there is no entry in the node table with the value 567890 for the ...

Get SQL Server 2017 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.