• Let me answer the questions as presented.

    > are there any alternatives that would be worth thinking about?

    Yes, but without a more specific problem domain, theory is about all we can offer you.

    could you also explain the line "GID int IDENTITY"? What does GID stand for / relate to?

    The simple answer is that GID stands for "Generated ID".  I use GID because "ID" is a reserved word in some databases.

    The longer answer is that every object in a database has at least four identifiers of interest.  A GID, an internal name, a business name, and a display label.  Not all identifiers are always used.  The GID is a numeric identifier that may be unique to the table, to the database, to a system, and so on.  GIDs are for use by the database for referential integrity and should never be used directly in a query.  For example, Select * from SomeTable where GID = 123 is forbidden.  Due to the nature of databases, GIDs can and do vary across database instances.  Ping me if you want more information on the other identifiers and when they are appropriate.  I will generate an article on the topic if there is sufficient interest.

    > is your solution by any chance related to dijkstras algorithm? or is that somethin different?

    dijkstras algorithm may be useful for this problem, depending on the real-world problem constraints.  The challenge with the algorithm is that the approach uses procedural logic rather than set-based logic.  As such, it is better suited for a procedural language.  When we add a database into the solution, we can precompute (and therefore store) most if not all of the possible information we need to solve the problem.  This reduces the actual run-time element to a single query which is typically much more efficient than the dynamic algorithm.  This is a very simplistic answer.  A real solution would need to involve a fully populated testbed with more constraints than we have yet identified.