CPS 353: Internet Programming

Database Schema (and maybe some other sql)

Marcos Elugardo

Gordon College

Last Modified: 10/03/2015

Selected content adapted from material by Kirk McClure.

Agenda

Notes should go here...

Check-in

Syllabus change

Mission statement

Mission statement

Define Mission Objectives

Mission Objectives

Identify the nouns

Identifying Characteristics

Review and Refine the List of Characteristics

Identify calculated characteristics

Defining the Final Table List

Some table examples

Subject
Description
Leagues
A sporting league.s organizational body. This allows owners to compete in multiple fantasy leagues and with alternate real-world organizations.
Owners
Team (or League) management. (Other) Owners are the user's competitors.
Teams
Contesting entity. Teams are the contestants.
Rosters
Players comprising a team during a defined period. Rosters record current and historical team compositions.
Players
Individual physical contestants. Players are the team components whose performances are scored.
Matchups
Schedule of head-to-head team competitions. Matchups record future and historical inter-team competitions.
OffenseStatistics
Performance for (QB, RB, TE, WR) offense players. Summaries of players' scoring components.
KickerStatistics
Performance for Place Kickers. Summaries of place kickers' scoring components.
DefenseStatistics
Performance for team Defenses. Summaries of team defense scoring components.

Associate fields with tables

Ideal fields

Ideal tables

Primary key

Elements of a primary key

Define data type for fields

Table relationships

Foreign Keys

Type of participation

Creating a table

CREATE TABLE [dbo].[Course]
(
	[CourseId] INT NOT NULL PRIMARY KEY IDENTITY, 
	[Title] VARCHAR(50) NOT NULL,
	[Description] VARCHAR(MAX),
	[StartDate] DATETIME2 NULL
)

Creating a table - 2 foreign keys

CREATE TABLE [dbo].[Enrollment]
(
	[EnrollmentId] INT NOT NULL PRIMARY KEY IDENTITY, 
    [StudentId] INT NOT NULL, 
    [CourseId] INT NOT NULL, 
    [Grade] INT NOT NULL DEFAULT 100,
	CONSTRAINT [FK_Enrollment_Student] 
		FOREIGN KEY ([StudentId]) REFERENCES [Student]([StudentId]),
	CONSTRAINT [FK_Enrollment_Course] 
		FOREIGN KEY ([CourseId]) REFERENCES [Course]([CourseId])
)

SQL for fantasy football tables

This is part of your homework. The sql in sql server is a little differnt than in mysql, so do not take examples from that database.

SQL

Tables

Join

SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
 JOIN Plantings
ON gid = gardener_id

Left Join

SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
LEFT JOIN Plantings
ON gid = gardener_id

Right Join

SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
RIGHT  JOIN Plantings
ON gid = gardener_id

Outer Join

SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
 OUTER JOIN Plantings
ON gid = gardener_id

Cross Join

SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
CROSS JOIN Plantings

Self Join

SELECT G1.gid, G1.first_name, G1.last_name, G2.gid, G2.first_name, G2.last_name
FROM Gardners G1
 JOIN Gardners G2 
ON G1.first_name = G2.first_name

Combined joins

SELECT G1.gid, G1.first_name, G1.last_name, G2.gid, 
		G2.first_name, G2.last_name, p.plant_name
FROM Gardners G1
JOIN Gardners G2 ON G1.first_name = G2.first_name
JOIN Plantings p
ON G1.gid = p.gardener_id
SQL Joins

Real world examples

Class Research topics on databases

Homework 4

Milestone 4