📄
EBIS3003-2021
  • Introduction to the Course
  • Preliminaries
    • donorschoose.org
    • Installing Software
    • Sequel Pro Local Access
    • Import donorschoose.org Data to MySQL Server
    • MySQL Setting for Client Software
  • SQL
    • Class Activity 2 - Creating New Tables (Week 2)
    • Inserting Table
    • Select / Functions
    • Grouping
  • PYTHON
    • Installing Anaconda
    • Running Jupyter Notebook
    • Connecting MySQL via Python
  • Assignments
    • In-class Activity - ER (Week 5)
    • Homework Assignment 1
      • Solutions
    • Homework Assignment 2
    • In-Class Activity - Python (Week 11-12)
    • In-Class Activity - Normalization (Week 14)
Powered by GitBook
On this page
  • Example SQL Code
  • A Simple Data Model

Was this helpful?

  1. SQL

Class Activity 2 - Creating New Tables (Week 2)

Example SQL Code

USE EBIS3003;

DROP TABLE IF EXISTS projects_kick;
DROP TABLE IF EXISTS creaotrs_kick;


CREATE TABLE creators_kick (
	id INT NOT NULL,
	user_id VARCHAR(255) NOT NULL,
	password VARCHAR(255) NOT NULL,
	num_projects INT NULL,
	address VARCHAR(255) NULL,
	bio LONGTEXT NULL,

	CONSTRAINT creators_key PRIMARY KEY(id)
);

CREATE TABLE projects_kick (
	id INT NOT NULL,
	creator_id INT NOT NULL,
	timestamp VARCHAR(255) NOT NULL,
	total_amount DECIMAL(10,3) NULL,
	completion INT NOT NULL,
	remaining_amount DECIMAL(10,3) NULL,

	CONSTRAINT projects_key PRIMARY KEY(id),
	CONSTRAINT projects_f_key FOREIGN KEY(creator_id) REFERENCES creators_kick(id) 
);

There are a few things to note:

  1. Transit to EBIS3003 database.

  2. DROP TABLE in case you made mistake before.

  3. VARCHAR v. VARCHAR2 v. CHAR.

    • The numbers are 'bytes,' not # of characters.

    • Difference between standard SQL v. MySQL (or other variations).

  4. CONSTRAINT can be omitted in MySQL.

  5. Use of NULL.

  6. INT and DECIMAL are different!

  7. The order of creating tables matter when you have constraints.

  8. The name of foreign key can be different from its original name in the referenced table.

A Simple Data Model

PreviousMySQL Setting for Client SoftwareNextInserting Table

Last updated 4 years ago

Was this helpful?

powered by

https://www.w3schools.com/sql/sql_datatypes.asp
https://dbdiagram.io/