Help:COAP-3180/hw3: Difference between revisions
Jump to navigation
Jump to search
m (→Play time) |
|||
Line 57: | Line 57: | ||
DROP TABLE IF EXISTS student; | DROP TABLE IF EXISTS student; | ||
DROP TABLE IF EXISTS | DROP TABLE IF EXISTS exercise; | ||
CREATE TABLE student ( | CREATE TABLE student ( | ||
Line 70: | Line 70: | ||
INSERT INTO student VALUES (NULL,'Testeuse','Sophie'); | INSERT INTO student VALUES (NULL,'Testeuse','Sophie'); | ||
CREATE TABLE | CREATE TABLE exercise ( | ||
id int(10) NOT NULL auto_increment, | id int(10) NOT NULL auto_increment, | ||
title char(40) DEFAULT '' NOT NULL, | title char(40) DEFAULT '' NOT NULL, | ||
Line 80: | Line 80: | ||
); | ); | ||
INSERT INTO | INSERT INTO exercise VALUES (NULL,"Exercise 1",'1',"small comment",'http://tecfa.unige.ch/'); | ||
INSERT INTO | INSERT INTO exercise VALUES (NULL,"Exercise 2",'1',"no comment",'http://tecfa.unige.ch/'); | ||
</pre> | </pre> |
Revision as of 18:26, 11 November 2007
Homework 3 - COAP 3180 Fall 2 2007
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.
Homework tasks
- Think about a simple web application that needs a database table, i.e. something that is quite similar to homework 1.
- With a simple text editor create a *.sql file and that includes the necessary SQL commands
- Import this file into a mySQL database
- Repair errors until it works
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:
Demo 1 example
CREATE TABLE demo1 ( 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, PRIMARY KEY (id), KEY login (login) );
Student database with 2 tables
DROP TABLE IF EXISTS student; DROP TABLE IF EXISTS exercise; CREATE TABLE student ( id int(10) NOT NULL auto_increment, name char(40) DEFAULT '' NOT NULL, first_name char(40) DEFAULT '' NOT NULL, PRIMARY KEY (id) ); 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, PRIMARY KEY (id), KEY student_id (student_id) ); INSERT INTO exercise VALUES (NULL,"Exercise 1",'1',"small comment",'http://tecfa.unige.ch/'); INSERT INTO exercise VALUES (NULL,"Exercise 2",'1',"no comment",'http://tecfa.unige.ch/');
Reading and links
Reading
Pick one of these. Some articles are presented as multiple pages (!)
- Introduction to Structured Query Language: Version 4.11 by James Hoffman.
- Getting Started With SQL by Ted Brockwood
- What is SQL?
- Introduction to Databases for the Web: Pt. 1 by Selena Sol (most complete article)
Reference
- SQL (follow up the links)
- MySQL 5 reference manual. See in particular