Search code examples
mysqlsqldatabasecreate-table

Creating a database table (MySQL)


I'm trying to create a database script that includes the SQL code for the following steps, and
execute each step using MySQL Workbench to create and populate a new table
called recipe in fooddb.

That recipe table should have columns for for the following object variables: id (using auto
increment), title, Instructions (just one string), numServings, and totalTime (in
minutes).

EDIT 3 - 11/4/2014 - 15:32... I may have figured it out, by I'm not too sure, however:

create table recipe ( 
RecipeID int not null auto_increment, 
'RecipeName' varchar(300), 
'RecipeType' varchar(100), 
"Instructions" text,
NumOfServings int not null,
TotalTimeInMinutes int not null,
primary key(RecipeID));

insert into recipe values (0, 'RecipeName', 'RecipeType', "Instructions", 0, 0); 

select * from recipe;

Is there anything that might be wrong with this?


Solution

  • You should take a look at the mysql manual to learn about creating databases/tables:

    Create Table Syntax

    there are also examples of how to create tables.

    Edit: you can do either:

    INSERT INTO recipe (name, category) VALUES ('Recipename', 'Categoryname');
    

    since you only specify the columns where you want to add data

    or

    INSERT INTO recipe VALUES (0, 'Recipename', 'CategoryName');
    

    because you have to give ALL data for all columns if you don't specify the columns.