HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Database Design: Storing Map Locations

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
locationsmapdesigndatabasestoring

Problem

When working on a game, I developed a database that used X/Y coordinates, roughly as:

CREATE TABLE Map
(
    MapId INT IDENTITY PRIMARY KEY,
    X INT NOT NULL,
    Y INT NOT NULL,
    North INT FOREIGN KEY REFERENCES Map(MapId),
    South INT FOREIGN KEY REFERENCES Map(MapId),
    East INT FOREIGN KEY REFERENCES Map(MapId),
    West INT FOREIGN KEY REFERENCES Map(MapId)
);


(I'm not at my editor, so that may have syntax errors.)

I then implemented the path searching algorithm (A*, specifically) inside a stored procedure.

-
Is there a better way to implement this coordinates system?

-
I had implemented it in SQL Server, since that is what I had on hand and what I was familiar with. Is there anything in another database system that would've simplified this problem?

It may make a difference to know that this, being a game, is strictly a grid system. That may simplify (or complicate) the problem.

Edit:

Some sample data:

map_id      x           y           north       east        south       west
----------- ----------- ----------- ----------- ----------- ----------- -----------
20          502         501         26          33          21          18
21          502         502         20          22          87          19
22          503         502         33          23          88          21

Solution

If the game area is strictly static, then my preference would be to use the coordinates as the primary key.

On postgres, I'd probably do that using a composite type. I don't think there is a direct equivalent in SQL Server - hopefully someone will correct me if I'm wrong.

Whether this will simplify the problem or not depends on how exactly you have implemented your searching algorithm - can you post more details on that?

Context

StackExchange Database Administrators Q#4670, answer score: 3

Revisions (0)

No revisions yet.