I've got a question relating databases which i can't find the anwser for myself. Currently i got a situation where i have a database with two tables. The two tables are named items and items_sequences. What i want to do is make a relationship between the primary key of the item database and a field in the items_sequences table. Below an illustrated example.
| Items | | items_sequences |
|-------| |------------------|
| id | | sequence_id |
| foo | | counter |
The point is creating the relationship isnt hard. But what i want to do if an Item is made an item sequence should be also made containing a sequence_id with the primary key of the Item itself. And if a Item is deleted the item_sequence should be deleted as well. By the way this should be a 1:1 relationship.
I forgot how this can be done, i would really appreciate if someone would point me to the right direction. Currently i am using a postgresq开发者_如何转开发l database if it matters.
Thanks,
Antek
If I get this right, you want to look into using foreign keys and triggers.
If it's a 1:1 relationship, could you not just combine the tables?
精彩评论