Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check out this <a href="http://www.tizag.com/mysqlTutorial/" rel="nofollow">link</a> for a mysql introduction and the <a href="http://en.wikipedia.org/wiki/Relational_database" rel="nofollow">wikipedia</a> article on relational databases. Read about tables, primary and foreign keys. Before worrying about performance you need to address the structure of your database.</p> <p>Try (<a href="http://www.tomjewett.com/dbdesign/dbdesign.php?page=association.php" rel="nofollow">One-to-Many</a>:A student can own many pieces of music and have one friend):</p> <pre><code>CREATE TABLE Student( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), first_name VARCHAR(30), last_name VARCHAR(30), friend_id INT) CREATE TABLE Music( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), music_title VARCHAR(30), music_student_id INT) FOREIGN KEY (music_student_id) REFERENCES Student(id) ON DELETE CASCADE </code></pre> <p>Or Try (<a href="http://www.tomjewett.com/dbdesign/dbdesign.php?page=manymany.php" rel="nofollow">Many-to-Many</a>:Many students can own many pieces of music and have many friends):</p> <pre><code>CREATE TABLE Student( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), first_name VARCHAR(30), last_name VARCHAR(30)) FOREIGN KEY (id) REFERENCES StudentMusic (Student_id) ON DELETE CASCADE CREATE TABLE Music( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), music_title VARCHAR(30), FOREIGN KEY (id) REFERENCES StudentMusic (Music_id) ON DELETE CASCADE CREATE TABLE StudentMusic ( Student_id INT NOT NULL AUTO_INCREMENT, Music_id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (Student_id,Music_id) CREATE TABLE Friendships( student_A_id INT, student_B_id INT) PRIMARY KEY (student_A_id,student_B_id) </code></pre> <p>Handling the data views of the relationships can be shown using a Select statement. In the One-to-Many design finding a Student's music uses the following query:</p> <pre><code>Select Student.first_name,Student.last_name,Music.music_title FROM Student LEFT JOIN Music on (Student.ID=Music.music_student_id) </code></pre> <p>Part of designing a database is figuring out what relationships you will need to query.</p> <p>Also look into <a href="http://en.wikipedia.org/wiki/Database_normalization" rel="nofollow">normalizing databases</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload