Ghanshyam
Ghanshyam

Reputation: 25

how to create a dynamic database ?

I want to create a dynamic database

with needed as step or flow on this basis..

how can i create database this by through store query or any other way.

I want to need a programmatically.

1)HEALTHY RECIPES CATEGORIES table

   1)BreakFast
   2)Lunch
   3)Dinner
   4)chicken & turkey
   5)Dessert 
   ...........

2) Breakfast table....

 - orange and vanilla protein oatmeal

 -chili-chocolote protein oatmeal
 .....

3) - orange and vanilla protein oatmeal table

  -Ingredients
  -directions

Thanks All to in Advance...

Upvotes: 0

Views: 851

Answers (1)

BartoszGo
BartoszGo

Reputation: 450

I understand that you'd like to use SQLite. Run SQLite client (Sqliteman or similar), create a new database and run the below as a script:

create table category (
  category_id integer not null primary key,
  name varchar(80) not null
);
create table meal (
  meal_id integer not null primary key,
  name varchar(80) not null,
  directions text
);
create table meal_category (
  meal_category_id integer primary key,
  meal_id integer not null references meal,
  category_id integer not null references category
);

You can then insert data like this:

insert into category (category_id, name) values (1, 'Breakfast');
insert into category (category_id, name) values (2, 'Lunch');
insert into meal (meal_id, name) values (1, 'Orange and vanilla protein oatmeal');
insert into meal (meal_id, name) values (2, 'Chili-chocolote protein oatmeal');
insert into meal_category (meal_category_id, meal_id, category_id) values (1, 1, 1); -- meal 1 is a breakfast
insert into meal_category (meal_category_id, meal_id, category_id) values (2, 2, 1); -- meal 2 is a breakfast

And query it like this:

select m.name || ' is ' || c.name from meal m
  join meal_category mc on m.meal_id = mc.meal_id
  join category c on mc.category_id = c.category_id;

It's the simplest design. You may want to add additional fields and some indexes - please check tutorials on SQL how to do it. Anyway the above will give you a working SQLite database.

You may need table "ingredient" which will keep data of anything which can be used for a recipe (egg, flour, water etc) and "meal_ingredient" which will tell if an ingredient should be present in a meal. Text of the recipe can be kept in meal.recipe field.

Note that there are different ways to design a database and typically you should provide a detailed specification of the system which will use the database to have a good design.

It's best if you think what the database will be used for, what kind of data you want to get from it and then read on SQL and do some experiments on your own. For example, if you want to be able to look for any meal which uses flour, it's best to have ingredients in a separate table, linked to meal - just like a category is linked to a meal, it's called a "many to many relationship". But if you don't care about such a functionality, both recipe and a list of ingredients could be put in meal.recipe field. Design of the database should reflect your needs and the part of reality you want to have a model of.

Upvotes: 1

Related Questions