CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.

Slides:



Advertisements
Similar presentations
Database Design Week 10.
Advertisements

SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
Introduction to Relational Database ISYS 464. Introduction to Relational Model Data is logically structured within relations. Each relation is a table.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Database Systems Lecture 5 Natasha Alechina
MySql In Action Step by step method to create your own database.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
Introduction to Internet Databases MySQL Database System Database Systems.
Deanery of Business & Computer Sciences SQL Structured Query Language Implementation Lecture – 8 Database Technology Level I.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
SQL Structured Query Language. Aims  To introduce the implementation of a Physical design using SQL.  To introduce SQL Data Definition Language (DDL).
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Jennifer Widom Relational Databases The Relational Model.
Chapter 3: Relational Databases
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 4 Database Design and ER Modeling This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
INF1343, Week 6 Implementing a Database with SQL This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT395, Week 11 Review, Permissions Physical Storage and Performance This presentation is licensed under Creative Commons Attribution License, v. 3.0.
Database Design and Implementation
CCT395, Week 2 Introduction to SQL Yuri Takhteyev September 15, 2010
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Week 4 Database Design and ER Modeling This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 5 Translating ER into Relations; Normalization This presentation is licensed under Creative Commons Attribution License, v To view a.
CCT395, Week 7 SQL with PHP This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit
CS SQL.
Database Design and Implementation
Translating ER into Relations; Normalization
Review Databases and Objects
CS320 Web and Internet Programming SQL and MySQL
Chapter 4 Logical Database Design and the Relational Model
SQL: Schema Definition and Constraints Chapter 6 week 6
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Special Topics in CCIT: Databases
CCT1343, Week 2 Single-Table SQL Yuri Takhteyev University of Toronto
Introduction to MySQL.
CS 3630 Database Design and Implementation
Database application MySQL Database and PhpMyAdmin
Database Design and Implementation
Data Modeling and Database Design
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Database Design and Implementation
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Database Management  .
Structured Query Language (Data definition Language)
ERD’s REVIEW DBS201.
Relational Databases The Relational Model.
Relational Databases The Relational Model.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Rob Gleasure robgleasure.com
CS3220 Web and Internet Programming SQL and MySQL
A Very Brief Introduction to Relational Databases
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
Turn on spool and save to file a.txt
MySQL Database System Installation Overview SQL summary
Database Instructor: Bei Kang.
Database 2.
Presentation transcript:

CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from Yuri Takhteyev University of Toronto October 13, 2010

Recursive Relationships employee salary supervise s

Recursive Relationships employee salary employee_id * supervise s

Step 3 “For each entity that is at the ‘many’ end of one or more relationships, include the primary key of each parent entity in the table as foreign keys.”

Recursive Relationships employee salary employee_id * supervise s

Recursive Relationships employee salary employee_id * employee_id supervise s

Recursive Relationships employee salary employee_id * supervisor_id supervise s

employee

1-1 Relationships chef name signature dish description

Option 1: Merge chef name signature dish description

Option 1: Merge chef

Option 2: FK as PK chef name signature dish description

Option 2: FK as PK chef chef_id* name signature dish description

Option 2: FK as PK chef chef_id* name signature dish chef_id* description

Option 2: FK as PK signature dish

Questions?

Database Design requirements analysis implementation deployment design

Database Design requirements analysis implementation deployment design

Database Design requirements analysis implementation deployment design loading data testing

Implementation - Create a database/schema - Define domains (not today) - Create the tables

Create a Database create database ; create database university; For instance:

Query OK, 1 row affected (0.00 sec)

Delete a Database drop database ; drop database university; For instance:

Query OK, 0 rows affected (0.01 sec)

Create a Table create table ; use university; create table student; For instance:

ERROR 1113 (42000): A table must have at least 1 column

Create a Table create table ( ); create table student (student_id int); For instance:

Query OK, 0 rows affected (0.02 sec)

Create a Table create table (, ); create table student ( student_id int, last_name varchar(100) ); For instance:

ERROR 1050 (42S01): Table 'student' already exists

Delete a Table drop table ; drop table student; For instance:

Query OK, 0 rows affected (0.00 sec)

Create a Table create table (, ); create table student ( student_id int, last_name varchar(100) ); For instance:

Query OK, 0 rows affected (0.02 sec)

Required Fields create table student ( student_id int not null, last_name varchar(100) );

Primary Keys create table student ( student_id int not null, last_name varchar(100), primary key (student_id) );

mysql> describe student; | Field | Type | Null | Key | Default | Extra | | student_id | int(11) | NO | PRI | NULL | | | last_name | varchar(100) | YES | | NULL | | rows in set (0.00 sec)

Foreign Keys create table enrollment ( student_id int not null, foreign key (student_id) references student(student_id), instance_id int not null );

Load Some Data! insert into student values ( 1, "Jones" );

Query OK, 1 row affected (0.00 sec) mysql> select * from student; | student_id | last_name | | 1 | Jones | row in set (0.00 sec)

From a File load data infile "/tmp/students.csv" into table student;

The File 1Jones tab

Comma-Separated load data infile "/tmp/students.csv" into table student fields terminated by ",";

Query OK, 1 row affected (0.00 sec) mysql> select * from student; | student_id | last_name | | 1 | Jones | row in set (0.00 sec) mysql> load data infile "/tmp/students.csv" into table student; ERROR 1062 (23000): Duplicate entry '1' for key 1

Deleting Data delete from student;

Deleting Select Data delete from student where... ;

Data 1273SmithRobert 1274Ivanov Boris 1275AlmeidaJoão

Easier SmithRobert IvanovBoris AlmeidaJoão

Auto-Increment create table student ( student_id int not null auto_increment, last_name varchar(100), primary key (student_id) );

Auto-Increment load data infile "/tmp/students.csv" into table student;

Auto-Increment insert into student (last_name) values ("Jones");

Questions?

João Almeida’s Fair Trade Coffee