Jump to content

MySQL Relational Database


Dysan

Recommended Posts

How do I convert the following database into a relational database? The database contains peoples favorite food and drinks.

 

if (mysql_query("CREATE DATABASE db",$con))
{
  echo "Database Created!";
}
else
{
  echo mysql_error();
}

mysql_select_db("db", $con);
$sql = "CREATE TABLE persons 
(
  name text,
)";

mysql_query($sql,$con);

$sql = "CREATE TABLE items 
(
  favouritedrink text,
  favouritefood text,  
)";

mysql_query($sql,$con);
mysql_close($con);

ad an id field on your person table, id int unsigned autoincrement primary key. then add a field on the items table called person_id int unsigned. relate the tables together by including the id of a record in the person table as the person_id for a record in the items table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.