Chapter 4: Intermediate SQL

Size: px
Start display at page:

Download "Chapter 4: Intermediate SQL"

Transcription

1 Chapter 4: Intermediate SQL Database System Concepts, 6 th Ed. See for conditions on re-use

2 4.1 Join Expressions Let s first review the joins from ch.3 4.2

3 1 SELECT * FROM student, takes WHERE student.id = takes.id; What s wrong with WHERE? Why do we need anything beyond it? 4.3

4 1 SELECT * FROM student, takes WHERE student.id = takes.id AND dept_name = 'Comp.Sci. ; Complicated queries are more readable if the join conditions are kept separate from the other WHERE conditions. 4.4

5 2 SELECT * FROM student NATURAL JOIN takes; 3 SELECT * FROM student JOIN takes USING(ID); 4.5

6 3 SELECT * FROM student JOIN takes ON student.id = takes.id; New syntax in ch.4! QUIZ: How can be make the ID to be displayed only once in the result? 4.6

7 To learn more More here about the history and motivations behind the join options in SQL: (linked on our webpage) 4.7

8 QUIZ: Create a table of room numbers associated with all the section IDs that were ever taught in those rooms. Use JOIN ON 4.8

9 Create a table of room numbers associated with all the section IDs that were ever taught in those rooms. SELECT C.room_no, S.sec_id FROM section AS S JOIN classroom AS C ON (C.room_no = S.room_no AND C.building = S.building); 4.9

10 Side note: The ON clause accepts any SQL predicate (<>, AND, OR, LIKE, BETWEEN, <=, etc.) SELECT C.room_no, S.sec_id FROM section AS S join classroom AS C ON(C.room_no >= S.room_no AND building LIKE 'Haunted %') but it s almost always used with = (or LIKE). 4.10

11 Problems when joining tables course prerequisite Write a query that returns all courses and their prerequisites. What happens with CS-315? Write a query that returns all courses in prereq and their information. What happens with CS-437? Conclusion: In either case, the tuples with unmatched attributes are missing! 4.11

12 Another reason to use JOIN instead of WHERE when joining tables: We are about to extend the concept of a JOIN! 4.12

13 4.1.2 Outer Joins They are extensions of the join operation that avoid the loss of information. After normally computing the join (now called inner join), they add tuples from one or both tables that do not match tuples in the other table. To do so, NULL values are inserted. 4.13

14 course Left Outer Join prerequisite SELECT * FROM course NATURAL LEFT OUTER JOIN prereq ; 4.14

15 course Right Outer Join prerequisite SELECT * FROM course NATURAL RIGHT OUTER JOIN prereq ; 4.15

16 course Full Outer Join prerequisite SELECT * FROM course NATURAL FULL OUTER JOIN prereq ; 4.16

17 QUIZ: Outer Joins Write a query to display a list of all students (ID and name), along with the courses they have taken. Hint: SELECT student.id, student.name FROM student NATURAL JOIN takes does not work for all cases (Why?) 4.17

18 solution Write a query to display a list of all students (ID and name), along with the courses they have taken. SELECT student.id, student.name FROM student NATURAL LEFT OUTER JOIN takes ; 4.18

19 Conclusion on Outer Joins Left Outer Join preserves tuples only on left relation Right Outer Joinpreserves tuples only on right relation Full Outer Join preserves tuples in both relations Join type defines how tuples in each relation that do not match any tuple in the other relation (based on the join condition) are treated. 4.19

20 Practice exercise 4.2 Rewrite SELECT * FROM student NATURAL LEFT OUTER JOIN takes ; without using the OUTER JOIN clause. Hint: An outer join is an inner join with some extra tuples added use UNION. 4.20

21 Rewrite SELECT * FROM student NATURAL LEFT OUTER JOIN takes ; without using the OUTER JOIN clause. ( Practice Exercise 4.2 ) ( ) 4.21

22 4.2 Views Remember the idea of abstraction from Ch.1! 4.22

23 4.2 Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) Consider a person who needs to know an instructors name and department, but not the salary. This person should see a relation described by SELECT ID, name, dept_name FROM instructor ; 4.23

24 4.2 Views SELECT ID, name, dept_name FROM instructor ; A view provides a mechanism to hide certain data from the view of certain users. Any relation that is not in the DM schema, but is made visible to a user as a virtual relation is called a view. 4.24

25 View Definition CREATE VIEW v AS < query expression > where: <query expression> is any legal SQL query. The view name is v. example 4.25

26 Example Parentheses are optional, but they increase readability! The view is listed in the catalog! 4.26

27 QUIZ: Create a view with all course sections offered by the Physics dept. in the Fall 2009 semester, with the building and room number of each section. CREATE VIEW phys_fall_2009 AS (? ); 4.27

28 QUIZ: Create a view with all course sections offered by the Physics dept. in the Fall 2009 semester, with the building and room number of each section. CREATE VIEW phys_fall_2009 AS ( ); 4.28

29 Extra-credit QUIZ 4.29

30 View nitty-gritty Once a view is defined, the view name can be used to refer to the virtual relation that the view generates. View definition is not the same as creating a new relation by evaluating the query expression Rather, the view definition causes only the saving of the SQL query expression The expression will later be substituted into any query that uses that view. A view is permanently deleted from the catalog using DROP VIEW v example 4.30

31 CREATE VIEW faculty AS ( SELECT ID, name, dept_name FROM instructor ); We can now use the view as a table to write queries, e.g. Find all instructors in the Biology department: SELECT name FROM faculty WHERE dept_name = ' Biology ; 4.31

32 View nitty-gritty Views can also be used to define other views: CREATE VIEW phys_fall_2009 AS CREATE VIEW phys_fall_2009_watson AS SELECT course_id, room_number FROM phys_fall_2009 WHERE building= Watson ; 4.32

33 How is this process implemented in SQL? Think about the C preprocessor create view physics_fall_2009 as select course.course_id, sec_id, building, room_number from course, section where course.course_id = section.course_id and course.dept_name = Physics and section.semester = Fall and section.year = 2009 ; create view physics_fall_2009_watson as select course_id, room_number from physics_fall_2009 where building= Watson ; This is called view expansion 4.33

34 View nitty-gritty The attribute names in a view can be specified explicitly: CREATE VIEW dept_sal (dept_name, total_salary) AS ( SELECT dept_name, SUM (salary) FROM instructor GROUP BY dept_name ); 4.34

35 Read and take notes: Materialized Views SQL does not define a standard way of specifying that a view is materialized, but many DBMSs provide their own SQL extensions for this task. In PostgreSQL: (Details in the lab) 4.35

36 4.2.4 Updating Views CREATE VIEW faculty AS ( SELECT ID, name, dept_name FROM instructor ); Add a new tuple to this view: INSERT INTO faculty VALUES ( 30765, Green, Music ); This insertion requires insertion of the tuple ( 30765, Green, Music, NULL) into the instructor relation. 4.36

37 NULL here! 4.37

38 Problem: Some updates cannot be translated uniquely! CREATE VIEW instructor_info AS SELECT ID, name, building FROM instructor NATURAL JOIN department ; INSERT INTO instructor_info VALUES ( 69987, White, Taylor ); Which department, if multiple departments in Taylor? What happens if there is no department in Taylor? 4.38

39 Next problem: Some updates should not be allowed at all! create view history_instructors as select * from instructor where dept_name= History ; What happens if we insert into this view the tuple ( 25566, Brown, Biology, )? 4.39

40 create view history_instructors as select * from instructor where dept_name= History ; What happens if we insert into this view the tuple ( 25566, Brown, Biology, )? If we allow insertion, the inserted tuple does not appear in the view! Should someone using this view even be allowed to insert instructors working in a different department? 4.40

41 Conclusion on updating views Most SQL implementations allow updates only on simple views, e.g. The from clause has only one database relation. The select clause contains only attribute names of the relation, and does not have any expressions, aggregates, or distinct specification. Any attribute not listed in the select clause can be set to null The query does not have a group by or having clause. 4.41

42 Updating views in PostgreSQL PostgreSQL has a proprietary extension to the CREATE VIEW syntax: (Details in the lab) 4.42

43 To do for next time: Read sections covered: 4.1, 4.2 Solve end-of-chapter exercises 4.3, EOL 1

44 QUIZ Write a query to return all sections, along with the ID of the instructor teaching them, even those not yet assigned to an instructor. 4.44

45 QUIZ Write a view to display only the sections taught in the Science building. 4.45

46 4.3 Transactions Transaction = Atomic unit of work = Sequence of operations that are either fully executed or rolled back as if none of them occurred Why do we need atomicity? Example: transferring money from account A to account B: Subtract amount from A Add amount to B What happens if the computer crashes here? 4.46

47 4.3 Transactions Aside from Atomicity, transaction-processing DBMSs must also ensure: Consistency Isolation Durability These are called the ACID properties (See Chs. 14, 15, 16 for details) 4.47

48 Transactions in PostgreSQL Not in text In PostgreSQL, a transaction is set up by surrounding the SQL commands of the transaction with BEGIN and COMMIT commands, e.g.: BEGIN; UPDATE accounts SET balance = balance WHERE name = 'Alice'; UPDATE accounts SET balance = balance WHERE name = Bob'; COMMIT; This example is based on the tutorial at

49 Not in text PostgreSQL treats every SQL statement as being executed within a transaction. If we don t issue a BEGIN command, then each individual statement has an implicit BEGIN and (if successful) COMMIT wrapped around it. A group of statements surrounded by BEGIN and COMMIT is called a transaction block. This example is based on the tutorial at

50 If, partway through the transaction, we decide we do not want to commit (perhaps we just noticed that Alice's balance went negative), we can issue the command ROLLBACK instead of COMMIT, and all our updates so far will be canceled, e.g.: BEGIN; UPDATE accounts SET balance = balance WHERE name = 'Alice'; UPDATE accounts SET balance = balance WHERE name = Bob'; -- Oops, now realizing the amount 150 was wrong ROLLBACK; Not in text This example is based on the tutorial at

51 QUIZ: Transactions in PostgreSQL Write a PostgreSQL query that increases the salaries of all instructors in the CS dept. by 6%, and those of all instructors in the Biology dept. by 5% atomically. 4.51

52 solution Write a PostgreSQL query that increases the salaries of all instructors in the CS dept. by 6%, and those of all instructors in the Biology dept. by 5% atomically. BEGIN; UPDATE instructor SET salary = salary * 1.06 WHERE dept_name = 'CS'; UPDATE instructor SET salary = salary * 1.05 WHERE dept_name = 'Biology'; COMMIT; 4.52

53 4.4 Integrity Constraints They guard against accidental damage to the DB, by ensuring that changes do not result in a loss of data consistency, e.g. A checking account must have a balance greater than $10, A salary of a bank employee must be at least $4.00 an hour A customer must have a (non-null) phone number 4.53

54 4.4 Integrity Constraints Integrity Constraints on a Single Relation NOT NULL PRIMARY KEY UNIQUE CHECK(P), where P is a predicate They can all be included in CREATE TABLE, or added later with ALTER TABLE. 4.54

55 UNIQUE ( A 1, A 2,, A m ) UNIQUE clause Typo on p.130 of text! States that the attributes A 1, A 2, A m form a candidate super key. Candidate keys are permitted to be null (in contrast to primary keys). If we want, we can add NOT NULL. Note: We have encountered the keyword UNIQUE in ch.3 (subqueries), but there it was part of the DML, whereas here it s part of the DDL. 4.55

56 check (P) where P is a predicate CHECK clause Example: ensure that semester is one of Fall, Winter, Spring or Summer: CREATE TABLE section ( course_id varchar (8), sec_id varchar (8), semester varchar (6), year numeric (4,0), building varchar (15), room_number varchar (7), time slot id varchar (4), PRIMARY KEY (course_id, sec_id, semester, year), CHECK (semester in ( Fall, Winter, Spring, Summer )) ); 4.56

57 Constraints on two relations: Referential Integrity Ensures that a value that appears in one relation for a given set of attributes also appears for a certain set of attributes in another relation. Example: If Biology is a department name appearing in one (or more) of the tuples in the instructor relation, then there exists a (unique!) tuple in the department relation for Biology. 4.57

58 What if an update (INSERT, DELETE, UPDATE) leads to violation of referential integrity? The normal procedure is to reject the action that caused the violation (the transaction performing the update action is rolled back). However, a foreign key clause can specify that instead of rejecting the action, the system must take steps to change the tuple in the referencing relation to restore the constraint. example 4.58

59 CREATE TABLE course ( course_id CHAR(5) PRIMARY KEY, title VARCHAR(20), dept_name VARCHAR(20) REFERENCES department ); CREATE TABLE course (.... dept_name VARCHAR(20) REFERENCES department ON DELETE CASCADE, ON UPDATE CASCADE ); Alternative actions: SET NULL, SET DEFAULT 4.59

60 Exercise 4.9 What happens when a tuple is deleted? (any tuple!) 4.60

61 Exercise 4.9 What happens when a tuple is deleted? (any tuple!) A: Due to cascading, all the tree of employees under the manager employee_name is deleted. 4.61

62 create table person ( ID char(10), name char(40), mother char(10), father char(10), primary key ID, foreign key father references person, foreign key mother references person); Integrity Constraint Violation During Transactions How to insert a tuple without causing constraint violation? insert father and mother of a person before inserting person OR, set father and mother to null initially, update after inserting all persons (not possible if father and mother attributes declared to be not null) OR defer constraint checking (next slide) 4.62

63 Deferred Constraints in PostgreSQL Upon creation, a constraint is given one of three characteristics: DEFERRABLE INITIALLY DEFERRED DEFERRABLE INITIALLY IMMEDIATE NOT DEFERRABLE. create table person ( ID char(10), name char(40), mother char(10), father char(10), primary key ID, foreign key father references person DEFERRABLE INITIALLY DEFERRED, foreign key mother references person) DEFERRABLE INITIALLY DEFERRED; Source:

64 Deferred Constraints in PostgreSQL Inside a transaction, the check will de deferred until right before the COMMIT, e.g. this transaction will succeed: BEGIN; INSERT INTO person VALUES ( 01, Kal-El, Jor-El, Lara ); INSERT INTO person VALUES ( 02, Jor-El, NULL, NULL ); INSERT INTO person VALUES ( 03, Lara, NULL, NULL ); COMMIT; 4.64

65 Complex CHECK conditions SQL standard says that the predicate can be anything, including a subquery! CHECK (time_slot_id IN ( SELECT time_slot_id FROM time_slot)); However, few DBMSs support subqueries in CHECK clause! (PostgreSQL doesn t.) CHECK is meant to handle constraints on a row's value in isolation. Alternatives: Triggers and functions (Ch.5) Assertions 4.65

66 Assertions CREATE ASSERTION <assertion-name> CHECK <predicate>; What integrity condition is enforced here? 4.66

67 Assertions CREATE ASSERTION <assertion-name> CHECK <predicate>; A: All tuples in student must have total credit equal to the sum of credits for the classes successfully completed. 4.67

68 QUIZ: Assertions Write an assertion to ensure that an instructor doesn t teach two different sections in the same year, semester and time slot. Use the previous assertion for example: 4.68

69 solution An instructor cannot teach two different sections in the same year, semester and time slot. CREATE ASSERTION non-ubiquity CHECK ( UNIQUE ( SELECT T.ID, T.semester, T.year, S.time_slot_id FROM teaches AS T NATURAL JOIN section AS S ) ); 4.69

70 4.5 SQL Data Types and Schemas Remember the basic data types (Sec.3.2): char(n) varchar(n) int smallint numeric(p,d) (user-specified precision) real, double precision (machine-dependent precision) float(n) (user-specified precision) 4.70

71 More data types: date and time date calendar date yyyy-mm-dd time hh:mm:ss timestamp combination date + time Example: :10: Fractions of a second are optional Timezone is optional 4.71

72 interval period of time Subtracting a date/time/timestamp value from another gives an interval value Interval values can be added to date/time/timestamp values, e.g. Source:

73 create table student ( ) Default values ID varchar (5), name varchar (20) not null, dept_name varchar (20) default qwerty tot_cred numeric (3,0) default 0, primary key (ID) 4.73

74 Index Creation create table student (ID varchar (5), name varchar (20) not null, dept_name varchar (20), tot_cred numeric (3,0) default 0, primary key (ID)); create index studentid_index on student(id); Index = data structure used to speed up access to records with specified values for index attributes, e.g. SELECT * FROM student WHERE ID = ; More details on indices in Chapter

75 Large-Object Types Large objects (photos, videos, CAD files, etc.) are stored as a large object: BLOB: binary large object -- object is a large collection of uninterpreted binary data (i.e. its interpretation is left to an application outside of the DB system) CLOB: character large object -- object is a large collection of character data CLOB is implemented as text in PostgreSQL (up to 1 GB) When a query returns a large object, a pointer is returned rather than the large object itself. 4.75

76 Read and take notes: User-Defined Types Schemas, Catalogs, and Environments 4.76

77 4.5.6 CREATE TABLE Extensions Applications often require creation of tables that have the same schema as an existing table: When writing a complex query, it is often useful to store the result of a query as a new table: How it this different from a view? 4.77

78 4.6 Authorization Forms of authorization on the data in the database: Read - allows reading, but not modification of data. Insert - allows insertion of new data, but not modification of existing data. Update - allows modification, but not deletion of data. Delete - allows deletion of data. Forms of authorization on the schema of the database: Index - allows creation and deletion of indices. Resources - allows creation of new relations. Alteration - allows addition or deletion of attributes in a relation. Drop - allows deletion of relations. 4.78

79 4.6 Authorization Read over lightly the remainder of this section 4.79

80 Homework for Ch.4 Due Thursday, Feb.23 - End of chapter 1, 3, 12, 14, 16 (Hint: CHECK), 18 - Table with all SQL constructs from ch.4, each used in an example (OK if example is from text) 4.80

81 Schema for University database 4.81

82 Schema for Bank database (fig.3.19) 4.82

Chapter 4: Intermediate SQL

Chapter 4: Intermediate SQL Chapter 4: Intermediate SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 4: Intermediate SQL Join Expressions Views Transactions Integrity Constraints SQL Data

More information

CS425 Fall 2017 Boris Glavic Chapter 5: Intermediate SQL

CS425 Fall 2017 Boris Glavic Chapter 5: Intermediate SQL CS425 Fall 2017 Boris Glavic Chapter 5: Intermediate SQL modified from: Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 5: Intermediate SQL Views Transactions Integrity

More information

Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata SQL 3 Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata Slides re-used, with minor modification, from Silberschatz, Korth and Sudarshan www.db-book.com Outline Join Expressions Views

More information

Chapter 4: Intermediate SQL

Chapter 4: Intermediate SQL Chapter 4: Intermediate SQL Chapter 4: Intermediate SQL Join Expressions Views Transactions Integrity Constraints SQL Data Types and Schemas Authorization Joined Relations Join operations take two relations

More information

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

Textbook: Chapter 4. Chapter 5: Intermediate SQL. CS425 Fall 2016 Boris Glavic. Chapter 5: Intermediate SQL. View Definition. Chapter 5: Intermediate SQL Views CS425 Fall 2013 Boris Glavic Chapter 5: Intermediate SQL Transactions Integrity Constraints SQL Data Types and Schemas Access Control Textbook: Chapter 4 5.2 Views View

More information

Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata SQL 4 Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata Slides re-used, with minor modification, from Silberschatz, Korth and Sudarshan www.db-book.com Outline Join Expressions Views

More information

MySQL Views & Comparing SQL to NoSQL

MySQL Views & Comparing SQL to NoSQL CMSC 461, Database Management Systems Fall 2014 MySQL Views & Comparing SQL to NoSQL These slides are based on Database System Concepts book and slides, 6 th edition, and the 2009/2012 CMSC 461 slides

More information

Lecture 6 - More SQL

Lecture 6 - More SQL CMSC 461, Database Management Systems Spring 2018 Lecture 6 - More SQL These slides are based on Database System Concepts book and slides, 6, and the 2009/2012 CMSC 461 slides by Dr. Kalpakis Dr. Jennifer

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

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

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query

More information

Explain in words what this relational algebra expression returns:

Explain in words what this relational algebra expression returns: QUIZ: Relational Algebra Explain in words what this relational algebra expression returns: A: The names of all customers who have accounts at both the Downtown and uptown branches 3.1 Practice Exercise

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

Principles of Data Management

Principles of Data Management Principles of Data Management Alvin Lin August 2018 - December 2018 Structured Query Language Structured Query Language (SQL) was created at IBM in the 80s: SQL-86 (first standard) SQL-89 SQL-92 (what

More information

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

The SQL data-definition language (DDL) allows defining : Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries

More information

Intermediate SQL ( )

Intermediate SQL ( ) CSL 451 Introduction to Database Systems Intermediate SQL (4.1-4.4) Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Summary Join

More information

CS425 Fall 2017 Boris Glavic Chapter 4: Introduction to SQL

CS425 Fall 2017 Boris Glavic Chapter 4: Introduction to SQL CS425 Fall 2017 Boris Glavic Chapter 4: Introduction to SQL Modified from: Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 4: Introduction to SQL Overview of the

More information

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

CSCB20 Week 2. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017 CSCB20 Week 2 Introduction to Database and Web Application Programming Anna Bretscher Winter 2017 This Week Quick Review of terminology Relational Model Continued Relational diagrams Relational operations

More information

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

CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model CS425 Fall 2016 Boris Glavic Chapter 2: Intro to Relational Model Modifies from: Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Textbook: Chapter 2 2.2 Example of a Relation

More information

Triggers- View-Sequence

Triggers- View-Sequence The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Database Lab (ECOM 4113) Lab 9 Triggers- View-Sequence Eng. Ibraheem Lubbad Triggers: A trigger is a PL/SQL block or

More information

QQ Group

QQ Group QQ Group: 617230453 1 Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join 2 Generalized Projection Extends the projection operation by allowing arithmetic functions

More information

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

CSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017 CSCB20 Week 4 Introduction to Database and Web Application Programming Anna Bretscher Winter 2017 Last Week Intro to SQL and MySQL Mapping Relational Algebra to SQL queries Focused on queries to start

More information

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

CSCB20. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017 CSCB20 Introduction to Database and Web Application Programming Anna Bretscher Winter 2017 Welcome to CSCB20 Course Description: A practical introduction to databases and Web app development. Databases:

More information

Relational model and basic SQL

Relational model and basic SQL 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

More information

Chapter 1: Introduction

Chapter 1: Introduction Chapter 1: Introduction Chapter 2: Intro. To the Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Database Management System (DBMS) DBMS is Collection of

More information

Unit 2: SQL AND PL/SQL

Unit 2: SQL AND PL/SQL Unit 2: SQL AND PL/SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Outline SQL: Characteristics and advantages, SQL Data Types and Literals, DDL, DML, DCL, TCL, SQL

More information

SQL Retrieving Data from Multiple Tables

SQL Retrieving Data from Multiple Tables The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Database Lab (ECOM 4113) Lab 5 SQL Retrieving Data from Multiple Tables Eng. Ibraheem Lubbad An SQL JOIN clause is used

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)

More information

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)

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) CS127 Homework #3 Warmup #1 Consider the following set of functional dependencies, F, for the schema R(A, B, C, D, E) 1. Find the candidate keys for the schema R. AB, C, D, and EA 2. Compute the closure,

More information

CS 582 Database Management Systems II

CS 582 Database Management Systems II Review of SQL Basics SQL overview Several parts Data-definition language (DDL): insert, delete, modify schemas Data-manipulation language (DML): insert, delete, modify tuples Integrity View definition

More information

Lab IV. Transaction Management. Database Laboratory

Lab IV. Transaction Management. Database Laboratory Lab IV Transaction Management Database Laboratory Objectives To work with transactions in ORACLE To study the properties of transactions in ORACLE Database integrity must be controlled when access operations

More information

Announcements (September 18) SQL: Part II. Solution 1. Incomplete information. Solution 3? Solution 2. Homework #1 due today (11:59pm)

Announcements (September 18) SQL: Part II. Solution 1. Incomplete information. Solution 3? Solution 2. Homework #1 due today (11:59pm) Announcements (September 18) 2 SQL: Part II Homework #1 due today (11:59pm) Submit in class, slide underneath my office door Sample solution available Thursday Homework #2 assigned today CPS 116 Introduction

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE 9/27/16 DATABASE SCHEMAS IN SQL SQL DATA DEFINITION LANGUAGE SQL is primarily a query language, for getting information from a database. SFWR ENG 3DB3 FALL 2016 But SQL also includes a data-definition

More information

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University Lecture 3 SQL Shuigeng Zhou September 23, 2008 School of Computer Science Fudan University Outline Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views

More information

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement Chapter 4 Basic SQL Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries,

More information

Chapter 13: Query Optimization

Chapter 13: Query Optimization Chapter 13: Query Optimization Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 13: Query Optimization Introduction Transformation of Relational Expressions Catalog

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)

More information

CSCB20 Week 3. 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 CSCB20 Week 3 Introduction to Database and Web Application Programming Anna Bretscher Winter 2017 This Week Intro to SQL and MySQL Mapping Relational Algebra to SQL queries We will focus on queries to

More information

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm)

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm) SQL: Part II CPS 116 Introduction to Database Systems Announcements (September 18) 2 Homework #1 due today (11:59pm) Submit in class, slide underneath my office door Sample solution available Thursday

More information

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

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints SQL KEREM GURBEY WHAT IS SQL Database query language, which can also: Define structure of data Modify data Specify security constraints DATA DEFINITION Data-definition language (DDL) provides commands

More information

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul 1 EGCI 321: Database Systems Dr. Tanasanee Phienthrakul 2 Chapter 10 Data Definition Language (DDL) 3 Basic SQL SQL language Considered one of the major reasons for the commercial success of relational

More information

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017 SQL: Data Definition Language csc343, Introduction to Databases Diane Horton Fall 2017 Types Table attributes have types When creating a table, you must define the type of each attribute. Analogous to

More information

Database System Concepts

Database System Concepts Chapter 4(+8): Advanced SQL Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and

More information

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Alexandra Roatiş David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2016 CS 348 SQL Winter

More information

SQL: Data Definition Language

SQL: Data Definition Language SQL: Data Definition Language CSC 343 Winter 2018 MICHAEL LIUT (MICHAEL.LIUT@UTORONTO.CA) DEPARTMENT OF MATHEMATICAL AND COMPUTATIONAL SCIENCES UNIVERSITY OF TORONTO MISSISSAUGA Database Schemas in SQL

More information

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13 CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible

More information

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

Chapter 7: Entity-Relationship Model. Chapter 7: Entity-Relationship Model Chapter 7: Entity-Relationship Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 7: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2017 CS 348 (Intro to DB Mgmt) SQL

More information

Slides by: Ms. Shree Jaswal

Slides by: Ms. Shree Jaswal Slides by: Ms. Shree Jaswal Overview of SQL, Data Definition Commands, Set operations, aggregate function, null values, Data Manipulation commands, Data Control commands, Views in SQL, Complex Retrieval

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features

More information

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601 Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Database Management System Subject Code: CS 601 Multiple Choice Type Questions 1. Data structure or the data stored

More information

Data Manipulation (DML) and Data Definition (DDL)

Data Manipulation (DML) and Data Definition (DDL) Data Manipulation (DML) and Data Definition (DDL) 114 SQL-DML Inserting Tuples INSERT INTO REGION VALUES (6,'Antarctica','') INSERT INTO NATION (N_NATIONKEY, N_NAME, N_REGIONKEY) SELECT NATIONKEY, NAME,

More information

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #4: SQL---Part 2

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #4: SQL---Part 2 CS 4604: Introduc0on to Database Management Systems B. Aditya Prakash Lecture #4: SQL---Part 2 Overview - detailed - SQL DML other parts: views modifications joins DDL constraints Prakash 2016 VT CS 4604

More information

SQL DDL II. CS121: Relational Databases Fall 2017 Lecture 8

SQL DDL II. CS121: Relational Databases Fall 2017 Lecture 8 SQL DDL II CS121: Relational Databases Fall 2017 Lecture 8 Last Lecture 2 Covered SQL constraints NOT NULL constraints CHECK constraints PRIMARY KEY constraints FOREIGN KEY constraints UNIQUE constraints

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2016 CS 348 (Intro to DB Mgmt) SQL

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns) tuples (or rows) 2.2 Attribute Types The

More information

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Language 4.1 Schema Used in Examples

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Re-accredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

Course Outline and Objectives: Database Programming with SQL

Course Outline and Objectives: Database Programming with SQL Introduction to Computer Science and Business Course Outline and Objectives: Database Programming with SQL This is the second portion of the Database Design and Programming with SQL course. In this portion,

More information

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

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See   for conditions on re-use Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " SQL Data Types and Schemas! Integrity Constraints! Authorization! Embedded SQL! Dynamic

More information

CS W Introduction to Databases Spring Computer Science Department Columbia University

CS W Introduction to Databases Spring Computer Science Department Columbia University CS W4111.001 Introduction to Databases Spring 2018 Computer Science Department Columbia University 1 in SQL 1. Key constraints (PRIMARY KEY and UNIQUE) 2. Referential integrity constraints (FOREIGN KEY

More information

Unit I. By Prof.Sushila Aghav MIT

Unit I. By Prof.Sushila Aghav MIT Unit I By Prof.Sushila Aghav MIT Introduction The Need for Databases Data Models Relational Databases Database Design Storage Manager Query Processing Transaction Manager DBMS Applications DBMS contains

More information

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210 SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique

More information

Unit 3 : Relational Database Design

Unit 3 : Relational Database Design Unit 3 : Relational Database Design Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Content Relational Model: Basic concepts, Attributes and Domains, CODD's Rules, Relational

More information

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture COGS 121 HCI Programming Studio Week 03 - Tech Lecture Housekeeping Assignment #1 extended to Monday night 11:59pm Assignment #2 to be released on Tuesday during lecture Database Management Systems and

More information

DB Creation with SQL DDL

DB Creation with SQL DDL DB Creation with SQL DDL Outline SQL Concepts Data Types Schema/Table/View Creation Transactions and Access Control Objectives of SQL Ideally, database language should allow user to: create the database

More information

Chapter 8: Relational Database Design

Chapter 8: Relational Database Design Chapter 8: Relational Database Design Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 8: Relational Database Design Features of Good Relational Design Atomic Domains

More information

Sql Server Syllabus. Overview

Sql Server Syllabus. Overview Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers

More information

Using a DBMS. Shan-Hung Wu & DataLab CS, NTHU

Using a DBMS. Shan-Hung Wu & DataLab CS, NTHU Using a DBMS Shan-Hung Wu & DataLab CS, NTHU DBMS Database A database is a collection of your data stored in a computer A DBMS (DataBase Management System) is a software that manages databases 2 Outline

More information

Chapter 7 Constraints and Triggers. Spring 2011 Instructor: Hassan Khosravi

Chapter 7 Constraints and Triggers. Spring 2011 Instructor: Hassan Khosravi Chapter 7 Constraints and Triggers Spring 2011 Instructor: Hassan Khosravi SQL: Constraints and Triggers Certain properties we d like our database to hold Modification of the database may break these properties

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business This is the second portion of the Database Design and Programming with SQL course. In this portion, students implement their database design by creating a

More information

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) SQL language Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) 2011-2016 SQL - Structured Query Language SQL is a computer language for communicating with DBSM Nonprocedural (declarative) language What

More information

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 13 Constraints & Triggers Hello and welcome to another session

More information

Lab # 4. Data Definition Language (DDL)

Lab # 4. Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with

More information

Part VIII Transactions, Integrity and Triggers

Part VIII Transactions, Integrity and Triggers Part VIII Transactions, Integrity and Triggers Transactions, Integrity and Triggers 1 Basic Terms 2 Term Transaction 3 Transactions in SQL 4 Integrity Constraints in SQL 5 Trigger Saake Database Concepts

More information

Relational Algebra and SQL

Relational Algebra and SQL Relational Algebra and SQL Computer Science E-66 Harvard University David G. Sullivan, Ph.D. Example Domain: a University We ll use relations from a university database. four relations that store info.

More information

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model Chapter 7: Entity-Relationship Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 7: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 2 Data Definition Language (DDL) Eng. Alaa O Shama October, 2015 Objective To be familiar

More information

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1 DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE Updating Databases Using SQL Specifying Constraints as Assertions and Actions as Triggers Schema Change Statements in

More information

Integrity and Security

Integrity and Security C H A P T E R 6 Integrity and Security This chapter presents several types of integrity constraints, including domain constraints, referential integrity constraints, assertions and triggers, as well as

More information

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model Chapter 7: Entity-Relationship Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 7: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information

CS6302 DBMS 2MARK & 16 MARK UNIT II SQL & QUERY ORTIMIZATION 1. Define Aggregate Functions in SQL? Aggregate function are functions that take a collection of values as input and return a single value.

More information

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL Faloutsos 15-415 Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications C. Faloutsos Lecture#7 (cont d): Rel. model - SQL part3 General Overview - rel. model Formal query languages

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and

More information

SQL: Part II. Introduction to Databases CompSci 316 Fall 2018

SQL: Part II. Introduction to Databases CompSci 316 Fall 2018 SQL: Part II Introduction to Databases CompSci 316 Fall 2018 2 Announcements (Thu., Sep. 20) Homework #1 sample solution to be posted on Sakai by this weekend Homework #2 due in 1½ weeks Get started on

More information

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints SQL: A COMMERCIAL DATABASE LANGUAGE Complex Constraints Outline 1. Introduction 2. Data Definition, Basic Constraints, and Schema Changes 3. Basic Queries 4. More complex Queries 5. Aggregate Functions

More information

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables INDEX Exercise No Title 1 Basic SQL Statements 2 Restricting and Sorting Data 3 Single Row Functions 4 Displaying data from multiple tables 5 Creating and Managing Tables 6 Including Constraints 7 Manipulating

More information

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4 SQL OVERVIEW CS121: Relational Databases Fall 2017 Lecture 4 SQL 2 SQL = Structured Query Language Original language was SEQUEL IBM s System R project (early 1970 s) Structured English Query Language Caught

More information

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 1 BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL Set Operations in SQL 3 BASIC SQL Structured

More information

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1 SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier

More information

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 1 BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 2 CHAPTER 4 OUTLINE SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL Set Operations in SQL 3 BASIC SQL Structured

More information

Databases. Jörg Endrullis. VU University Amsterdam

Databases. Jörg Endrullis. VU University Amsterdam Databases Jörg Endrullis VU University Amsterdam The Relational Model Overview 1. Relational Model Concepts: Schema, State 2. Null Values 3. Constraints: General Remarks 4. Key Constraints 5. Foreign Key

More information

SQL. SQL DDL Statements

SQL. SQL DDL Statements SQL Structured Query Language Declarative Specify the properties that should hold in the result, not how to obtain the result Complex queries have procedural elements International Standard SQL1 (1986)

More information

ER to Relational Model. Professor Jessica Lin

ER to Relational Model. Professor Jessica Lin ER to Relational Model Professor Jessica Lin 1 Reduction to Relation Schemas Entity sets and relationship sets can be expressed uniformly as relation schemas that represent the contents of the database.

More information

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Comp 5311 Database Management Systems. 4b. Structured Query Language 3 Comp 5311 Database Management Systems 4b. Structured Query Language 3 1 SQL as Data Definition Language Creates the Students relation. The type (domain) of each field is specified, and enforced by the

More information

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1 COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE

More information

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model Chapter 7: Entity-Relationship Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 7: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information