How to create a database with parent-child relationships?

If I needed to represent, for example, locations (e.g. countries, states / regions, regions, cities, etc.) in a database, how would I do it in such a way that it would be easier to request, most, etc. ? I plan to use this for an application that will allow users to select multiple locations and associate them with their profile.

The solution that comes to mind is the following:

===========================
| Id | ParentId | Name    |
===========================
| 1  | 0        | USA     |
---------------------------
| 2  | 1        | Alabama |
---------------------------

I am wondering if there are any potential problems with such a solution. Thank.

+5
source share
4 answers

( ), . .

, , .

!

+3

, / ( , ).

(, ..). , , , , .

, , , , , , .

0

. .

(, ) . . , , , , .

0

, .

0

All Articles