QuestionQ1

Design and develop database solutions

You have an Azure SQL database containing these SQL graph tables:

  • A NODE table named dbo.Person
  • An EDGE table named dbo.Knows

Each row in dbo.Person contains these columns:

  • PersonID (int)
  • DisplayName (nvarchar(100))

You need to use a MATCH operator with exactly two directed Knows relationships to return the PersonID and DisplayName of people reachable from the person identified by an input parameter named @StartPersonId.

Which Transact-SQL query should you use?

Explanation

A directed SQL Graph pattern uses arrows to specify the traversal direction. The pattern p1-(k1)->p2-(k2)->p3 traverses exactly two directed Knows edges from the starting node p1 to p3; filtering p1.PersonID by @StartPersonId establishes the origin, and selecting p3.PersonID and p3.DisplayName returns the people reached after the second relationship. Microsoft documents that MATCH patterns traverse from one node to another through an edge in the arrow’s specified direction.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!