Reputation: 169
So I created a recipe database, and just now I've noticed I forgot to add an ingredient to the second recipe. The order of ingredients is obviously important here, so even if I add it now to the end of the table, it will still be the last when I SELECT
the second recipe, when it should be the second ingredient.
Is there any way I can insert it in a specific position, or am I doomed and will have to create an index
column specifying the order of the ingredients?
NOTE: This is a junction table, so there's no primary key here, thus I can't insert it using a specific primary key value.
EDIT: Basically I have three tables: Recipe
, Ingredient
, and RecipeIngredient
many-to-many junction table.
Here's the RecipeIngredient
junction table structure:
RecipeId: FK
IngredientId: FK
Quantity: REAL
UOM: TEXT
Notes: TEXT
Upvotes: 2
Views: 455
Reputation: 16687
The rules of the First normal form (1NF) are strict on this:
Meaning there is no way, in a proper database schema, that a record can be "missing at a certain position".
You are indeed "doomed" and
will have to create an index column specifying the order of the ingredients
Upvotes: 1
Reputation: 152
can you show the table structure? It is difficult to insert a row in specific position without primary key.
Upvotes: 0