Relational model and basic SQL

Similar documents
CSCB20 Week 2. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

CSCB20. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

CSCB20 Week 3. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Lecture 6 - More SQL

MySQL Views & Comparing SQL to NoSQL

CSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Other Relational Languages

The En'ty Rela'onship Model

Chapter 3: Introduction to SQL

Chapter 7: Entity-Relationship Model. Chapter 7: Entity-Relationship Model

Indexing: B + -Tree. CS 377: Database Systems

Chapter 3: Introduction to SQL

CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model

The SQL data-definition language (DDL) allows defining :

Chapter 2 Introduction to Relational Models

Relational Algebra. Procedural language Six basic operators

CS425 Fall 2013 Boris Glavic Chapter 7: Entity-Relationship Model!

Chapter 11: Indexing and Hashing" Chapter 11: Indexing and Hashing"

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Chapter 4: Intermediate SQL

Chapter 6: Formal Relational Query Languages

CS127 Homework #3. Due: October 11th, :59 P.M. Consider the following set of functional dependencies, F, for the schema R(A, B, C, D, E)

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation!

Chapter 4: Intermediate SQL

Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

CS 582 Database Management Systems II

QQ Group

Explain in words what this relational algebra expression returns:

CS425 Fall 2017 Boris Glavic Chapter 4: Introduction to SQL

CSC 343 Winter SQL: Aggregation, Joins, and Triggers MICHAEL LIUT

Introduction CHAPTER. 1.1 Database-System Applications

Physical Database Design

Textbook: Chapter 4. Chapter 5: Intermediate SQL. CS425 Fall 2016 Boris Glavic. Chapter 5: Intermediate SQL. View Definition.

Chapter 4: Intermediate SQL

CS425 Fall 2017 Boris Glavic Chapter 5: Intermediate SQL

ERRATA for Database System Concepts, 6 th Edition, 2010 Silberschatz, Korth, and Sudarshan Last updated: December 6, 2010

SQL Retrieving Data from Multiple Tables

Chapter 7: Entity-Relationship Model

Unit1: Introduction. Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

CS425 Midterm Exam Summer C 2012

Database index structures

Entity-Relationship Model

Unit 2: SQL AND PL/SQL

Chapter 2: Relational Model

Chapter 2: Intro to Relational Model

Chapter 7: Entity-Relationship Model

ER to Relational Model. Professor Jessica Lin

Chapter 7: Entity-Relationship Model

Roadmap of This Lecture. Weak Entity Sets Extended E-R Features Reduction to Relation Schemas Database Design UML*

Chapter 1: Introduction

Chapter 7: Entity-Relationship Model

Indexing: Overview & Hashing. CS 377: Database Systems

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

Chapter 6 Formal Relational Query Languages

Natural-Join Operation

Unit I. By Prof.Sushila Aghav MIT

Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Relational Database Design (II)

Principles of Data Management

Chapter 11: Indexing and Hashing

Chapter 11: Indexing and Hashing

Instructor: Amol Deshpande

Relational Model. CSC 343 Winter 2018 MICHAEL LIUT

Final Review. CS 377: Database Systems

Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

CS3DB3/SE4DB3/SE6M03 TUTORIAL

Functional dependency theory

Chapter 8: Relational Database Design

Normalisation theory

Triggers- View-Sequence

Database Management Systems,

CS3DB3/SE4DB3/SE6M03 TUTORIAL

Chapter 2: Intro to Relational Model

Unit 3 : Relational Database Design

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects

Relational Model. Nisa ul Hafidhoh

Database Management Systems

Introduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

CS143: Relational Model

7) To be considered a composite key, a key must contain at least two attributes. Answer: TRUE

Chapter 11: Indexing and Hashing

Relational Algebra and SQL

Introduction to Database Management Systems

Chapter 7: Entity-Relationship Model. CS425 Fall 2016 Boris Glavic. Chapter 7: Entity-Relationship Model. Database Design.

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

CS425 Fall 2016 Boris Glavic Chapter 1: Introduction

CS275 Intro to Databases

2.2.2.Relational Database concept

CMPT 354: Database System I. Lecture 2. Relational Model

The Extended Algebra. Duplicate Elimination. Sorting. Example: Duplicate Elimination

Database Technology Introduction. Heiko Paulheim

Lecture 2: Introduction to SQL

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

DBMS. Relational Model. Module Title?

Relational Model. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

SQL Functions (Single-Row, Aggregate)

Lecture 1: Relational Databases

QUIZ: Buffer replacement policies

Query Processing & Optimization

Database Management Systems,

Transcription:

Relational model and basic SQL Introduction to Database Design 2011, Lecture 2 Relational model and keys Basic SQL - Creating tables - Inserting rows - Retrieving information - Joins Overview 2

Relational databases A logical view of databases, due to E. F. Codd, 1970 Data stored in tables (aka relations) columns (aka attributes) rows (aka tuples) 3 Basic terminology A relation schema is a set of attributes A database schema is a set table names along with corresponding relation schemas A relation instance is a relation schema and a set of tuples 4

A candidate key is minimal set of attributes that characterises tuples uniquely A primary key is a chosen candidate key In the instructor table ID is the primary key Keys 5 Composite primary keys Primary keys can consist of more than one attribute Table: classroom ------------- building room_number capacity ------------- Packard 101 500 Painter 514 10 Taylor 3128 70 Watson 101 30 Watson 120 50 ------------- Primary key consists of building and room_number 6

Foreign keys are references to other tables primary keys The instructor table The department table 7 Notation for schemas instructor (ID, name, dept_name, salary) department (dept_name, building, budget) classroom (building, room_number, capacity) 8

Schema diagrams 9 SQL

Structured Query Language SQL SQL used for many purposes - as a data definition language for defining database schemas - as a data manipulation language for manipulating data - as a query language for retrieving data 11 Data definition in SQL create table instructor! (ID!! varchar(5),! name!!! varchar(20),! dept_name varchar(20),! salary!! numeric(8,2),! primary key (ID),! foreign key (dept_name) references department); create table department! (dept_name varchar(20),! building!! varchar(15),! budget!! numeric(12,2),! primary key (dept_name)); create table classroom! (building!! varchar(15),! room_number!varchar(7),! capacity!! numeric(4,0),! primary key (building, room_number)); 12

Foreign keys in MySQL On ITU s MySQL system, the standard engine does not enforce primary keys InnoDB does create table instructor! (ID!!! varchar(5),! name!! varchar(20), dept_name varchar(20),! salary!! numeric(8,2),! primary key (ID),! foreign key (dept_name) references department(dept_name)) ENGINE = InnoDB; create table department! (dept_name varchar(20),! building! varchar(15),! budget!! numeric(12,2),! primary key (dept_name)) ENGINE = InnoDB; Note also, here name of key attribute is specified 13 SQL types SQL type Describes Example int Integers 12 numeric(12,2) decimal number 12,34 varchar(40) text Volvo text text, no size limit Volvo date date 2010-11-26 time time 09:30 datetime date and time 2010-11-26 09:30 14

Inserting one row Inserting many rows Data manipulation in SQL insert into department values ('Biology', 'Watson', '90000'); insert into department values ('Biology', 'Watson', '90000'), ('History', 'Painter', '50000'); Inserts may not break uniqueness constraint for primary keys Alternative syntax insert into department (dept_name, building, budget) values ('Biology', 'Watson', '90000'), ('History', 'Painter', '50000'); 15 Deleting all rows Data manipulation in SQL delete from department; Can also be modified to delete only certain rows Deleting rows and schema drop table department; 16

Queries: retrieving information Queries in SQL mysql> select * from classroom; ------------- building room_number capacity ------------- Packard 101 500 Painter 514 10 Taylor 3128 70 Watson 101 30 Watson 120 50 ------------- 5 rows in set (0.00 sec) 18

Queries in SQL mysql> select building, room_number from classroom; -------------+ building room_number -------------+ Packard 101 Painter 514 Taylor 3128 Watson 101 Watson 120 -------------+ 5 rows in set (0.01 sec) 19 Queries in SQL mysql> select building from classroom; building Packard Painter Taylor Watson Watson 5 rows in set (0.01 sec) 20

Queries in SQL mysql> select * from classroom where building = 'Watson'; ------------- building room_number capacity ------------- Watson 101 30 Watson 120 50 ------------- 2 rows in set (0.00 sec) 21 Queries in SQL mysql> select room_number from classroom where building = 'Watson'; +-------------+ room_number +-------------+ 101 120 +-------------+ 2 rows in set (0.00 sec) 22

Projection in the relational model Projecting on name and salary select name, salary from instructor; 23 Selection in the relational model select * from instructor where salary > 90000; 24

Combining selection and projection select name, dept_name from instructor where salary > 90000; First select, then project 25 Operations in the relational model Selection and projection take tables and return tables But result may contain duplicates select dept_name from instructor; 26

Can repair this by using keyword distinct Distinct mysql> select dept_name from instructor; +------------+ dept_name +------------+ Biology Comp. Sci. Comp. Sci. Comp. Sci. Elec. Eng. Finance Finance History History Music Physics Physics +------------+ 12 rows in set (0.00 sec) mysql> select distinct dept_name from instructor; +------------+ dept_name +------------+ Biology Comp. Sci. Elec. Eng. Finance History Music Physics +------------+ 7 rows in set (0.00 sec) 27 Selecting on combinations of features mysql> select name from instructor -> where salary > 90000 -> and dept_name = "Physics"; name Einstein 1 row in set (0.00 sec) mysql> select name from instructor -> where salary > 90000 -> or dept_name = "Physics"; name Einstein Gold Brandt 3 rows in set (0.00 sec) 28

Joins Queries on multiple relations Recall mysql> select * from instructor; +-------+------------+------------ ID name dept_name salary +-------+------------+------------ 10101 Srinivasan Comp. Sci. 65000.00 12121 Wu Finance 90000.00 15151 Mozart Music 40000.00 22222 Einstein Physics 95000.00 32343 El Said History 60000.00 33456 Gold Physics 87000.00 45565 Katz Comp. Sci. 75000.00 58583 Califieri History 62000.00 76543 Singh Finance 80000.00 76766 Crick Biology 72000.00 83821 Brandt Comp. Sci. 92000.00 98345 Kim Elec. Eng. 80000.00 +-------+------------+------------ 12 rows in set (0.00 sec) mysql> select * from department; +-----------------------+ dept_name building budget +-----------------------+ Biology Watson 90000.00 Comp. Sci. Taylor 100000.00 Elec. Eng. Taylor 85000.00 Finance Painter 120000.00 History Painter 50000.00 Music Packard 80000.00 Physics Watson 70000.00 +-----------------------+ 7 rows in set (0.00 sec) 30

Queries on multiple relations mysql> select * from instructor, department; +-------+------------+-----------------------------------+ ID name dept_name salary dept_name building budget +-------+------------+-----------------------------------+ 10101 Srinivasan Comp. Sci. 65000.00 Biology Watson 90000.00 10101 Srinivasan Comp. Sci. 65000.00 Comp. Sci. Taylor 100000.00 10101 Srinivasan Comp. Sci. 65000.00 Elec. Eng. Taylor 85000.00 10101 Srinivasan Comp. Sci. 65000.00 Finance Painter 120000.00 10101 Srinivasan Comp. Sci. 65000.00 History Painter 50000.00 10101 Srinivasan Comp. Sci. 65000.00 Music Packard 80000.00 10101 Srinivasan Comp. Sci. 65000.00 Physics Watson 70000.00 12121 Wu Finance 90000.00 Biology Watson 90000.00 12121 Wu Finance 90000.00 Comp. Sci. Taylor 100000.00 12121 Wu Finance 90000.00 Elec. Eng. Taylor 85000.00 12121 Wu Finance 90000.00 Finance Painter 120000.00 12121 Wu Finance 90000.00 History Painter 50000.00 12121 Wu Finance 90000.00 Music Packard 80000.00 12121 Wu Finance 90000.00 Physics Watson 70000.00 15151 Mozart Music 40000.00 Biology Watson 90000.00 15151 Mozart Music 40000.00 Comp. Sci. Taylor 100000.00 15151 Mozart Music 40000.00 Elec. Eng. Taylor 85000.00 15151 Mozart Music 40000.00 Finance Painter 120000.00 15151 Mozart Music 40000.00 History Painter 50000.00... +-------+------------+-----------------------------------+ 84 rows in set (0.01 sec) 31 Joining relations mysql> select * from instructor, department -> where instructor.dept_name = department.dept_name; +-------+------------+-----------------------------------+ ID name dept_name salary dept_name building budget +-------+------------+-----------------------------------+ 10101 Srinivasan Comp. Sci. 65000.00 Comp. Sci. Taylor 100000.00 12121 Wu Finance 90000.00 Finance Painter 120000.00 15151 Mozart Music 40000.00 Music Packard 80000.00 22222 Einstein Physics 95000.00 Physics Watson 70000.00 32343 El Said History 60000.00 History Painter 50000.00 33456 Gold Physics 87000.00 Physics Watson 70000.00 45565 Katz Comp. Sci. 75000.00 Comp. Sci. Taylor 100000.00 58583 Califieri History 62000.00 History Painter 50000.00 76543 Singh Finance 80000.00 Finance Painter 120000.00 76766 Crick Biology 72000.00 Biology Watson 90000.00 83821 Brandt Comp. Sci. 92000.00 Comp. Sci. Taylor 100000.00 98345 Kim Elec. Eng. 80000.00 Elec. Eng. Taylor 85000.00 +-------+------------+-----------------------------------+ 12 rows in set (0.00 sec) 32

Natural join mysql> select * from instructor natural join department; +------------+-------+----------------------+-----------+ dept_name ID name salary building budget +------------+-------+----------------------+-----------+ Comp. Sci. 10101 Srinivasan 65000.00 Taylor 100000.00 Finance 12121 Wu 90000.00 Painter 120000.00 Music 15151 Mozart 40000.00 Packard 80000.00 Physics 22222 Einstein 95000.00 Watson 70000.00 History 32343 El Said 60000.00 Painter 50000.00 Physics 33456 Gold 87000.00 Watson 70000.00 Comp. Sci. 45565 Katz 75000.00 Taylor 100000.00 History 58583 Califieri 62000.00 Painter 50000.00 Finance 76543 Singh 80000.00 Painter 120000.00 Biology 76766 Crick 72000.00 Watson 90000.00 Comp. Sci. 83821 Brandt 92000.00 Taylor 100000.00 Elec. Eng. 98345 Kim 80000.00 Taylor 85000.00 +------------+-------+----------------------+-----------+ 12 rows in set (0.01 sec) Natural join compares column names Does not depend on foreign keys 33 First compute cartesian product The select only matching tuples Natural joins operationally mysql> select * from instructor natural join department; Finally project to get rid of duplicate attributes 34

Selecting on natural joins mysql> select * from instructor natural join department -> where salary > 70000; +------------+----------------------------+ dept_name ID name salary building budget +------------+----------------------------+ Biology 76766 Crick 72000.00 Watson 90000.00 Comp. Sci. 45565 Katz 75000.00 Taylor 100000.00 Comp. Sci. 83821 Brandt 92000.00 Taylor 100000.00 Elec. Eng. 98345 Kim 80000.00 Taylor 85000.00 Finance 12121 Wu 90000.00 Painter 120000.00 Finance 76543 Singh 80000.00 Painter 120000.00 Physics 22222 Einstein 95000.00 Watson 70000.00 Physics 33456 Gold 87000.00 Watson 70000.00 +------------+----------------------------+ 8 rows in set (0,00 sec) 35 Example Find all students whose advisors make more than $70000 Best advise I can give: - Start by solving an easier problem - Try to gather all the information needed first 36

Example mysql> select * from advisor; +-------+-------+ s_id i_id +-------+-------+ 12345 10101 44553 22222 45678 22222 00128 45565 76543 45565 23121 76543 98988 76766 76653 98345 98765 98345 +-------+-------+ mysql> select * from student join advisor on student.id = s_id; +--------------------------+-------+ ID name dept_name tot_cred s_id i_id +--------------------------+-------+ 12345 Shankar Comp. Sci. 32 12345 10101 44553 Peltier Physics 56 44553 22222 45678 Levy Physics 46 45678 22222 00128 Zhang Comp. Sci. 102 00128 45565 76543 Brown Comp. Sci. 58 76543 45565 23121 Chavez Finance 110 23121 76543 98988 Tanaka Biology 120 98988 76766 76653 Aoi Elec. Eng. 60 76653 98345 98765 Bourikas Elec. Eng. 98 98765 98345 +--------------------------+-------+ 9 rows in set (0,00 sec) 37 Example mysql> select * from (student join advisor on student.id = s_id) join instructor on i_id = instructor.id; +--------------------------+-------+-------+------------+------------ ID name dept_name tot_cred s_id i_id ID name dept_name salary +--------------------------+-------+-------+------------+------------ 12345 Shankar Comp. Sci. 32 12345 10101 10101 Srinivasan Comp. Sci. 65000.00 44553 Peltier Physics 56 44553 22222 22222 Einstein Physics 95000.00 45678 Levy Physics 46 45678 22222 22222 Einstein Physics 95000.00 00128 Zhang Comp. Sci. 102 00128 45565 45565 Katz Comp. Sci. 75000.00 76543 Brown Comp. Sci. 58 76543 45565 45565 Katz Comp. Sci. 75000.00 23121 Chavez Finance 110 23121 76543 76543 Singh Finance 80000.00 98988 Tanaka Biology 120 98988 76766 76766 Crick Biology 72000.00 76653 Aoi Elec. Eng. 60 76653 98345 98345 Kim Elec. Eng. 80000.00 98765 Bourikas Elec. Eng. 98 98765 98345 98345 Kim Elec. Eng. 80000.00 +--------------------------+-------+-------+------------+------------ 9 rows in set (0,00 sec) mysql> select student.name -> from (student join advisor on student.id = s_id) join instructor on i_id = instructor.id -> where salary > 70000; name Peltier Levy Zhang Brown Chavez Tanaka Aoi Bourikas 8 rows in set (0,00 sec) 38

Example, alternative solution mysql> select * from student, advisor, instructor where student.id = s_id and instructor.id = i_id; +--------------------------+-------+-------+------------+------------ ID name dept_name tot_cred s_id i_id ID name dept_name salary +--------------------------+-------+-------+------------+------------ 12345 Shankar Comp. Sci. 32 12345 10101 10101 Srinivasan Comp. Sci. 65000.00 44553 Peltier Physics 56 44553 22222 22222 Einstein Physics 95000.00 45678 Levy Physics 46 45678 22222 22222 Einstein Physics 95000.00 00128 Zhang Comp. Sci. 102 00128 45565 45565 Katz Comp. Sci. 75000.00 76543 Brown Comp. Sci. 58 76543 45565 45565 Katz Comp. Sci. 75000.00 23121 Chavez Finance 110 23121 76543 76543 Singh Finance 80000.00 98988 Tanaka Biology 120 98988 76766 76766 Crick Biology 72000.00 76653 Aoi Elec. Eng. 60 76653 98345 98345 Kim Elec. Eng. 80000.00 98765 Bourikas Elec. Eng. 98 98765 98345 98345 Kim Elec. Eng. 80000.00 +--------------------------+-------+-------+------------+------------ 9 rows in set (0,01 sec) mysql> select student.name from student, advisor, instructor -> where student.id = s_id and instructor.id = i_id -> and salary > 70000; name Peltier Levy Zhang Brown Chavez Tanaka Aoi Bourikas 8 rows in set (0,00 sec) 39 Suppose we want to find all information on courses and their prerequisites Renaming mysql> select * from prereq; +-----------+-----------+ course_id prereq_id +-----------+-----------+ BIO-301 BIO-101 BIO-399 BIO-101 CS-190 CS-101 CS-315 CS-101 CS-319 CS-101 CS-347 CS-101 EE-181 PHY-101 +-----------+-----------+ 7 rows in set (0,00 sec) mysql> select * from course; +-----------+----------------------------+------------+---------+ course_id title dept_name credits +-----------+----------------------------+------------+---------+ BIO-101 Intro. to Biology Biology 4 BIO-301 Genetics Biology 4 BIO-399 Computational Biology Biology 3 CS-101 Intro. to Computer Science Comp. Sci. 4 CS-190 Game Design Comp. Sci. 4 CS-315 Robotics Comp. Sci. 3 CS-319 Image Processing Comp. Sci. 3 CS-347 Database System Concepts Comp. Sci. 3 EE-181 Intro. to Digital Systems Elec. Eng. 3 FIN-201 Investment Banking Finance 3 HIS-351 World History History 3 MU-199 Music Video Production Music 3 PHY-101 Physical Principles Physics 4 +-----------+----------------------------+------------+---------+ 13 rows in set (0,00 sec) 40

Renaming mysql> select * from course natural join prereq; +-----------+---------------------------+------------+---------+-----------+ course_id title dept_name credits prereq_id +-----------+---------------------------+------------+---------+-----------+ BIO-301 Genetics Biology 4 BIO-101 BIO-399 Computational Biology Biology 3 BIO-101 CS-190 Game Design Comp. Sci. 4 CS-101 CS-315 Robotics Comp. Sci. 3 CS-101 CS-319 Image Processing Comp. Sci. 3 CS-101 CS-347 Database System Concepts Comp. Sci. 3 CS-101 EE-181 Intro. to Digital Systems Elec. Eng. 3 PHY-101 +-----------+---------------------------+------------+---------+-----------+ 7 rows in set (0,00 sec) mysql> mysql> select * from (course natural join prereq) join course on course_id = prereq_id; ERROR 1066 (42000): Not unique table/alias: 'course' mysql> select * from (course natural join prereq) join course as pre on pre.course_id = prereq_id; +-----------+---------------------------+------------+---------+-----------+-----------+----------------------------+------------+---------+ course_id title dept_name credits prereq_id course_id title dept_name credits +-----------+---------------------------+------------+---------+-----------+-----------+----------------------------+------------+---------+ BIO-301 Genetics Biology 4 BIO-101 BIO-101 Intro. to Biology Biology 4 BIO-399 Computational Biology Biology 3 BIO-101 BIO-101 Intro. to Biology Biology 4 CS-190 Game Design Comp. Sci. 4 CS-101 CS-101 Intro. to Computer Science Comp. Sci. 4 CS-315 Robotics Comp. Sci. 3 CS-101 CS-101 Intro. to Computer Science Comp. Sci. 4 CS-319 Image Processing Comp. Sci. 3 CS-101 CS-101 Intro. to Computer Science Comp. Sci. 4 CS-347 Database System Concepts Comp. Sci. 3 CS-101 CS-101 Intro. to Computer Science Comp. Sci. 4 EE-181 Intro. to Digital Systems Elec. Eng. 3 PHY-101 PHY-101 Physical Principles Physics 4 +-----------+---------------------------+------------+---------+-----------+-----------+----------------------------+------------+---------+ 7 rows in set (0,00 sec) 41 Renaming Suppose we want names of departments with budget larger than biology mysql> select * from department; +-----------------------+ dept_name building budget +-----------------------+ Biology Watson 90000.00 Comp. Sci. Taylor 100000.00 Elec. Eng. Taylor 85000.00 Finance Painter 120000.00 History Painter 50000.00 Music Packard 80000.00 Physics Watson 70000.00 +-----------------------+ 7 rows in set (0.00 sec) This doesn t quite work: select dept_name from department, department where budget > budget and dept_name = "Biology"; 42

Renaming We need two copies of department, and they need different names mysql> select T.dept_name -> from department as T, department as S -> where T.budget > S.budget -> and S.dept_name = "Biology"; +------------+ dept_name +------------+ Comp. Sci. Finance +------------+ 2 rows in set (0.00 sec) 43 After this week you should Understand concepts of primary and foreign keys Be able to draw schema diagrams Be able to write SQL statements using - create table - insert into - select from... where Explain meaning of simple queries using relational model 44