The educational technology and digital learning wiki
Jump to navigation Jump to search

1 Homework 3 - COAP 3180 Fall 2 2007

COAP 3180 Course Page

2 Summary

Continue the activity started in the classroom, i.e.

  • Define a SQL table with an SQL file
  • Create the table in a MySQL database by importing the file with the SQL instructions

Purpose: Become familiar with SQL table definitions and MySQL database management

Note: You will have to turn in a first version of this homework next Monday (week 4). We then will discuss what you should add to this mini-project.

3 Homework tasks

3.1 Part I

  1. Think about a simple web application that needs a database table, i.e. something that is quite similar to homework 1.
  2. With a simple text editor create a *.sql file and that includes the necessary SQL commands for creating a table
    • Note: Do not try to use all possible SQL datatypes. In most cases INT, VARCHAR, TEXT etc will do.
  3. Import this file into a mySQL database
  4. Repair errors until it works ...
  5. Add some data (either use the phpmyadmin interface or write INSERT statements

3.2 Part II

  1. Create an insert/query interface to your simple table with a php/mysql code generator
  2. You will have to to demonstrate this application next Monday (week 5)

We suggest to install either:

4 Play time

Warning. Be careful with quotes and double quotes.

  • Quotes must be straight (same for double quotes).
 '  = Ok
 ’  = BAD !!!

... So use a real text editor and not a word processor.

Fallback in case you don't have your own database:

4.1 Demo 1 example

  id int(10) NOT NULL auto_increment,
  login char(10) DEFAULT '' NOT NULL,
  password char(100),
  fullname char(40) DEFAULT '' NOT NULL,
  url char(60) DEFAULT '' NOT NULL,
  food int(11) DEFAULT '0' NOT NULL,
  work int(11) DEFAULT '0' NOT NULL,
  love int(11) DEFAULT '0' NOT NULL,
  leisure int(11) DEFAULT '0' NOT NULL,
  sports int(11) DEFAULT '0' NOT NULL,
  KEY login (login)

4.2 Student database with 2 tables


CREATE TABLE student (
  id int(10) NOT NULL auto_increment,
  name char(40) DEFAULT '' NOT NULL,
  first_name char(40) DEFAULT '' NOT NULL,

INSERT INTO student VALUES (NULL,'Testeur','Bill');
INSERT INTO student VALUES (NULL,'Testeur','Joe');
INSERT INTO student VALUES (NULL,'Testeuse','Sophie');

CREATE TABLE exercise (
  id int(10) NOT NULL auto_increment,
  title char(40) DEFAULT '' NOT NULL,
  student_id int(10) NOT NULL,
  comments varchar(128),
  url char(60) DEFAULT '' NOT NULL,
  KEY student_id (student_id)

INSERT INTO exercise VALUES (NULL,"Exercise 1",'1',"small comment",'');
INSERT INTO exercise VALUES (NULL,"Exercise 2",'1',"no comment",'');

5 Reading and links

5.1 Reading

Pick one of these. Some articles are presented as multiple pages (!)

5.2 Reference

5.3 Slides