Android SQLite. One to many relationship

My question is to work with sqlite and android.

I have this application that will record locations, and for each location the user will be able to add photos.

I have a table for

locations(loc_id INTEGER, longitude REAL ,latitude REAL)

which works great. But I need to create a second photo. In the photo table, the name of the photo path will be indicated as TEXT. It should also have another field that refers to a specific location through loc_idas a foreign key. The fact is, I don’t know how to connect the two.

Any help is greatly appreciated!

+4
source share
1 answer
CREATE TABLE locations(
  loc_id INTTEGER PRIMARY KEY, 
  longitude REAL,
  latitude REAL
);

CREATE TABLE photos(
  photo_id INTEGER PRIMARY KEY, 
  path TEXT, 
  fk_location INTEGER,
  FOREIGN KEY(fk_location) REFERENCES locations(loc_id)
);
+9

All Articles