Review of SQL. Review of SQL Slide 1 of 46

Size: px
Start display at page:

Download "Review of SQL. Review of SQL Slide 1 of 46"

Transcription

1 Review of SQL 5DV120 Database System Principles Umeå University Department of Computing Science Stephen J. Hegner Review of SQL Slide 1 of 46

2 About these Slides These slides are mostly adapted from those for 5DV119 by the same instructor. The adaptations use the schema of the Silberschatz-Korth-Sudarsham textbook, rather than that of the Elmasri-Navathe textbook. These slides will be used as a refresher/review, and will be covered much more rapidly than in the introductory course. They are intended for those who already know/knew SQL, but need a quick refresher. Review of SQL Slide 2 of 46

3 The SQL Standard SQL is the standard language for access to relational databases. There have been many standard versions, beginning with SQL92, and currently ending with SQL:2011. But many of its features have evolved from earlier vendor-specific ones. As a result, almost no relational DBMS follows the standard very closely. Even the most basic things, such as the data types representing dates and times, differ from system to system and greatly limit code portability. Most systems implement a superset of a subset of the standard specification. Nevertheless, the basic features of most systems are very similar, even if not completely compatible. In this course, the focus will be upon these basic features. To the extent that special features are needed, the open-source system PostgreSQL will be used. Review of SQL Slide 3 of 46

4 SQL consists of several parts: The Parts of SQL DDL: The data-definition language provides commands for defining and altering database schemata, including integrity constraints and virtual relations called views.. DML: The data-manipulation language provides commands for both querying and updating databases. Transactions: There are basic SQL commands for specifying transactions. These are limited in scope and most systems have their own ways of managing transactions. Authorization: SQL contains directives for granting and revoking privileges. Access from a host languages: SQL contains some basic commands for use when the language is embedded in a host programming language. These are limited in scope and many approaches to hosting SQL, including ODBC, have their own ways of of doing similar things. The last two topics are not covered in this course. Review of SQL Slide 4 of 46

5 Clients for Direct Access to SQL via PostgreSQL 8.4 The best way to access PostgreSQL is via the command-line interface: psql --username <username> --hostname <servername> <dbname> or psql -U <username> -h <servername> <dbname> <username> and <dbname> are usually the same on the systems of the department. <hostname> is postgres on the systems of the department. With ident authentication, no special password is used. \d shows a list of system commands. Use ctrl-z and then kill the process if parsing becomes too confused. Review of SQL Slide 5 of 46

6 Clients for Direct Access to SQL via PostgreSQL 9.1 For PostgreSQL 9.1, the server is postgres9. The instructions on the previous slide are therefore applicable, with postgres replaced with postgres9. Keep in mind that these are separate systems with separate databases. Since the client on the departmental systems is for version 8 of PostgresSQL, you are also allowed to log onto the machine socker, which has a version of the client which matches PostgreSQL 9.1. Review of SQL Slide 6 of 46

7 Defining Tables CREATE TABLE department ( dept_name VARCHAR (20), building VARCHAR (15), budget NUMERIC (12,2) CHECK ( budget > 0), PRIMARY KEY ( dept_name ) ); CREATE TABLE instructor (ID VARCHAR (5), name VARCHAR (20) NOT NULL, dept_name VARCHAR (20), salary NUMERIC (8,2) CHECK ( salary > 29000), PRIMARY KEY (ID), FOREIGN KEY ( dept_name ) REFERENCES department ON DELETE SET NULL ); department dept name building budget instructor id name dept name salary Review of SQL Slide 7 of 46

8 Defining Tables 2 CREATE TABLE Student ( Name VARCHAR (40) NOT NULL, Personnr CHAR (11) NOT NULL, Ident VARCHAR (8) NOT NULL, Status VARCHAR (3), PRIMARY KEY ( ident ), UNIQUE ( Personnr ) ); ); CREATE TABLE ObligEx ( Ident VARCHAR (10) NOT NULL, Number INTEGER NOT NULL, Grade INTEGER NOT NULL, Handedin DATE, Graded DATE, Approved DATE, Status CHAR (1), PRIMARY KEY ( ident, number ), CONSTRAINT obligex_ident_fkey FOREIGN KEY ( ident ) REFERENCES Student ( ident ) ON UPDATE CASCADE Student Ident PersonNr Name ObligEx Ident Number Grade HandedIn Graded Approved Status Review of SQL Slide 8 of 46

9 Adding Constraints to Tables CREATE TABLE instructor ( ID VARCHAR (5) NOT NULL, dept_name CHAR (9), Foreign key to department cannot be declared here. -- forward reference : FOREIGN KEY ( dept_name ) REFERENCES department CREATE TABLE department ( dept_name VARCHAR (20),... PRIMARY KEY ( dept_name ), ); -- Add the foreign - key constraint here : ALTER TABLE instructor ADD CONSTRAINT Instr_FK1 FOREIGN KEY ( dept_name ) REFERENCES Department ( dept_name ); Added constraints must be named. Instr FK1 is the name of the above constraint. Review of SQL Slide 9 of 46

10 Adding Constraints to Tables 2 CREATE TABLE instructor ( ID VARCHAR (5) NOT NULL, dept_name CHAR (9), Foreign key to department cannot be declared here. -- forward reference : FOREIGN KEY ( dept_name ) REFERENCES department CREATE TABLE department ( dept_name VARCHAR (20), -- Add a new attribute identifying the head of the department dept_head VARCHAR (5)... PRIMARY KEY ( dept_name ), FOREIGN KEY ( dept_head ) REFERENCES instructor ( ID ); ); -- The foreign - key constraint must be added here : ALTER TABLE instructor ADD CONSTRAINT Instr_FK1 FOREIGN KEY ( dept_name ) REFERENCES Department ( dept_name ); department dept name building budget dept head instructor id name dept name salary Review of SQL Slide 10 of 46

11 The Basic From of a Query The basic form of an SQL query is as follows. SELECT < attributes > FROM < tables > WHERE < conditions > The WHERE part is optional but most interesting queries require it. A very simple query: SELECT name, salary ; Star captures all attributes: SELECT * ; A simple condition: SELECT name, salary WHERE dept_name = Comp. Sci. ; Review of SQL Slide 11 of 46

12 Renaming the Columns of a Query Columns may be given explicit names using the AS directive. SELECT name AS Nachname, salary AS Gehalt WHERE ( salary >= 65000) OR ( dept_name = History ); These names will appear as the column headers. However, such name changes cannot be used as aliases in the WHERE clause. Does not work: SELECT name AS Nachname, salary AS Gehalt WHERE ( Gehalt >= 65000) OR ( dept_name = History ); The use of AS in the FROM clause has different scoping, as will be illustrated in examples to follow. Review of SQL Slide 12 of 46

13 Duplicates and Order SELECT salary ; SELECT DISTINCT salary -- Duplicates removed ; SELECT name, salary ORDER BY salary DESC ; -- DESCending order SELECT name, salary ORDER BY salary ASC ; -- ASCending order SELECT name, salary, ID ORDER BY name, salary, ID; -- Major - to - minor order ; Review of SQL Slide 13 of 46

14 Queries on Two Relations Problem: For each building, find the names of the instructors whose department is in that building. This query requires information from both the instructor and the department relations. A first try: SELECT building, name FROM department, instructor ; Does this work? No, it generates the Cartesian product of the two relations. A join condition is required: SELECT building, name FROM department, instructor WHERE ( department. dept_name = instructor. dept_name ); Note also the name resolution. Review of SQL Slide 14 of 46

15 The JOIN Operation of SQL The join operation is used so often that SQL has a special notation for it. SELECT building, name FROM department INNER JOIN instructor ON ( department. dept_name = instructor. dept_name ); is equivalent to SELECT building, name FROM department, instructor WHERE ( department. dept_name = instructor. dept_name ); The keyword INNER may be omitted. Such queries may include a WHERE clause as well. SELECT building, name FROM department INNER JOIN instructor ON ( department. dept_name = instructor. dept_name ) WHERE ( salary > 50000); Review of SQL Slide 15 of 46

16 The Natural Join of SQL When the names of the columns to be joined are the same in both relations, instead of using inner join, the natural join operation may be used. SELECT * FROM department NATURAL JOIN instructor ; is almost equivalent to SELECT * FROM department INNER JOIN instructor ON ( department. dept_name = instructor. dept_name ); The difference is that matching columns are not repeated in the natural join, while they are in the inner join. The match is on all columns with matching names in the relations. If there are no matching columns, the Cartesian product is the result (which is almost never what is intended). Try the following query to see this effect: SELECT * FROM classroom NATURAL JOIN instructor ; Review of SQL Slide 16 of 46

17 Aliases and Self Joins Query: Find all pairs of departments which are housed in the same building. It is necessary to use aliases: or SELECT D1. dept_name, D2. dept_name FROM department AS D1 JOIN department AS D2 ON (D1. building =D2. building ); SELECT D1. dept_name, D2. dept_name FROM department AS D1, department AS D2 WHERE (D1. building =D2. building ); Review of SQL Slide 17 of 46

18 Theta Joins Join conditions need not be based only upon equality. Joins based upon other comparison operators are often called theta joins. Query: Find those instructors whose salary is greater than the department budget. SELECT DISTINCT ID, name JOIN department ON (( instructor. dept_name = department. dept_name ) AND ( salary > budget )); Review of SQL Slide 18 of 46

19 Set and Multiset Operations in SQL Queries return multisets of tuples. Multiset: A set in which elements may occur more than once. The usual set operations apply to multisets in SQL. Name Symbol SQL union UNION intersection INTERSECT difference \ or EXCEPT Some implementations of SQL do not support INTERSECT and EXCEPT. Example: Mostly, these are small single-user systems such as MS Access. Example: MySQL is alone amongst major systems which do not support these set operations. Later, it will be shown how to achieve the same results using embedded subqueries. Review of SQL Slide 19 of 46

20 Embedded Subqueries It is often useful, if not essential, to be able to use subqueries in the WHERE clause of a query. Query: Find all instructors who work in the same department as Srinivasan. When a subquery returns a set consisting of just one tuple, the result may be regarded as a tuple. SELECT * WHERE dept_name = ( SELECT dept_name WHERE name = Srinivasan ); Note the lexical scoping of variables! An alternative using IN (set membership ): SELECT * WHERE dept_name IN ( SELECT dept_name WHERE name = Srinivasan ); Review of SQL Slide 20 of 46

21 Queries with Existential Quantification Query: Find all instructors who teach or have taught a section of a course which Srinivasan has also taught. SELECT DISTINCT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE course_id IN ( SELECT course_id FROM teaches WHERE id IN ( SELECT id WHERE ( name = Srinivasan ))); Exclude Srinivasan from the list. SELECT DISTINCT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE course_id IN ( SELECT course_id FROM teaches WHERE id IN ( SELECT id WHERE ( name = Srinivasan ))) AND (name <> Srinivasan ); Review of SQL Slide 21 of 46

22 Realizing INTERSECT Using Subqueries As already noted, some relational systems do not support the INTERSECT operation. Query: Find those instructors who teach or have taught both CS-101 and CS-319. SELECT DISTINCT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -101 ) INTERSECT SELECT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -319 ); Fortunately, this operation can be realized using subqueries. SELECT DISTINCT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -101 ) AND ( instructor. ID IN ( SELECT instructor. ID JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -319 ))); Only the key ID need be used in the subquery. Review of SQL Slide 22 of 46

23 Realizing EXCEPT Using Subqueries Some systems do not support the EXCEPT operation. Query: Find those instructors who teach or have taught CS-101 but not CS-319. SELECT DISTINCT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -101 ) EXCEPT SELECT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -319 ); Fortunately, this operation can be realized using subqueries. SELECT DISTINCT instructor. ID, name JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -101 ) AND ( NOT ( instructor.id IN ( SELECT instructor. ID JOIN teaches ON ( instructor. ID = teaches. ID) WHERE ( course_id = CS -319 )))); Only the key ID need be used in the subquery. Review of SQL Slide 23 of 46

24 Queries with Universal Quantification Query: Find all instructors who teach or have taught every course which Srinivasan also teaches or has taught. Exclude Srinivasan himself. At first sight, this appears to be impossible with SQL. However, it may be rephrased as a double negation: Find all instructors I for which there is no course C which Srinivasan teaches but I does not. This operation is formally known as division and is studied more carefully in connection with the relational algebra. SELECT DISTINCT Ins. ID, name AS Ins JOIN teaches ON ( Ins. ID = teaches. ID) WHERE NOT EXISTS ( SELECT course_id FROM teaches WHERE ( ID IN ( SELECT ID WHERE ( name = Srinivasan ))) EXCEPT ( SELECT course_id FROM teaches WHERE ( Ins.ID= teaches.id ))) AND NOT ( Ins. ID IN ( SELECT ID WHERE ( name = Srinivasan ))); Review of SQL Slide 24 of 46

25 Queries which Count (without Aggregation) Query: Find all instructors who teach at least two distinct courses. SELECT DISTINCT instructor. ID, name JOIN teaches AS T1 ON ( instructor. ID = T1. ID) JOIN teaches AS T2 ON ( instructor.id=t2.id) WHERE (T1. course_id <>T2. course_id ); Query: Find all instructors who teach exactly one course. SELECT DISTINCT instructor. ID, name WHERE EXISTS ( SELECT * FROM teaches WHERE ( instructor.id= teaches.id )) AND NOT EXISTS ( SELECT * FROM teaches AS T1 JOIN Teaches AS T2 ON (T1.ID=T2.ID) WHERE (T1. course_id <>T2. course_id ) AND (T1.ID= instructor.id )); Exercise: Find all instructors who teach exactly two courses. Review of SQL Slide 25 of 46

26 ALL and ANY Query: Find the instructors(s) with the highest salary. SELECT DISTINCT ID, name WHERE salary >= ALL ( SELECT salary ); Query: Find the instructors(s) with salaries which are not the lowest. SELECT DISTINCT ID, name, salary WHERE salary > ANY ( SELECT salary ); Review of SQL Slide 26 of 46

27 Pattern Matching in SQL SQL has two features for pattern matching: LIKE: uses a special syntax. SIMILAR TO: uses regular expressions. Query: Find all instructors whose names begin with the letter C. % is the wildcard symbol for LIKE. The following works in both PostgreSQL and MySQL: SELECT ID, name WHERE name LIKE C% ; MySQL uses case-insensitive matching, and so the following there, but in PostgreSQL it only finds names beginning with a lower-case c. SELECT ID, name WHERE name LIKE c% ; LIKE in PostgreSQL uses case-sensitive matching, Use ILIKE for case-insensitive matching. SELECT ID, name Review of SQL WHERE name ILIKE c% ; Slide 27 of 46

28 Pattern Matching in SQL Using SIMILAR TO MySQL does not support SIMILAR TO, although it is part of the SQL:1999 standard. Here are some examples which run under PostgreSQL: Query: Find all instructors whose names begin with the letter C. SELECT ID, name WHERE name SIMILAR TO C% ; SELECT ID, name WHERE name SIMILAR TO C[a-z]* ; Underscore matches a single character with both SIMILAR TO and LIKE. SELECT ID, name WHERE name SIMILAR TO C ; Review of SQL Slide 28 of 46

29 Additional Examples of Pattern Matching Query: Find the ID and name of all instructors whose ID has 3 or 8 as the third digit from the left. SELECT ID, name WHERE (ID LIKE 3 % ) OR (ID LIKE 8 % ); SIMILAR TO has a built-in disjunction operator: SELECT ID, name WHERE ID SIMILAR TO (3 8)% ; Tilde is the escape character for both operators. Query: Find the IDs and names of instructors containing the character %: SELECT name WHERE name LIKE %~%% ; Review of SQL Slide 29 of 46

30 Basic Update Operations in SQL There are three basic forms of update in SQL: Insertion: Using the INSERT directive, new tuples may be added to a relation. Deletion: Using the DELETE directive, existing tuples may be removed from a relation. Modification: Using the UPDATE directive, the values in fields of existing tuples may be changed. A note on terminology: The word update has two distinct meanings, both of which are entrenched in the database literature and practice. 1. In the general database literature, an update may refer to any operation which changes of the state of a database. 2. In SQL, an update refers to a modification of an existing tuple or tuples. It is necessary to resolve which of these two meanings is intended by using context. Review of SQL Slide 30 of 46

31 The SQL INSERT Directive There are two basic forms of insertion: In the first, all fields for a single tuple are specified from left to right: INSERT INTO instructor VALUES ( 00000, Ortega, NULL, ); In the second, fields may be listed in any order and missing fields are taken to be NULL: INSERT INTO instructor ( ID, name, salary ) VALUES ( 00000, Ortega, ); In both cases, the insertion will fail if any integrity constraint would be violated by the insertion. There is also a third form of insertion which involves views (not considered here). Review of SQL Slide 31 of 46

32 The SQL DELETE Directive Deletion involves the use of a WHERE clause to identify the tuples to be deleted.: DELETE WHERE ID= ; In contrast to the INSERT directive, DELETE may remove several tuples at once. DELETE WHERE dept_name = Comp. Sci. ; Deletion can never cause a violation of a PRIMARY KEY or UNIQUE constraint, but it is possible for a FOREIGN KEY to be violated. The deletion is not executed if it would cause such a violation. Review of SQL Slide 32 of 46

33 The SQL UPDATE Directive Modification via UPDATE involves the use of a SET clause to identify the changes and a WHERE clause to identify the tuples to be modified: UPDATE instructor SET dept_name = Comp. Sci. WHERE ID= ; UPDATE may modify several tuples at once. UPDATE instructor SET SALARY = SALARY WHERE dept_name = Comp. Sci. ; Modification can cause a violation of a PRIMARY KEY or UNIQUE constraint only if it alters the value of a primary or candidate key. Other forms of constraints may be violated, however. The deletion is not executed if it would cause such a violation. Review of SQL Slide 33 of 46

34 Multiple Updates and Integrity Constraints By default, integrity constraints are checked after each INSERT, DELETE, and UPDATE operation, which can lead to intermediate inconsistency. Consider again the augmented university schema in which each department has a head. department dept name building budget dept head instructor id name dept name salary Example: Add the new instructor Ortega and make him head of the newly added Management department. INSERT INTO instructor VALUES ( 00000, Ortega, Management, ); INSERT INTO department VALUES ( Management, Watson, , ); Regardless of which order these operations are executed, a violation of a foreign-key constraint will result. In PostgreSQL and most other major systems, the solution involves DEFERRABLE constraints and explicit transactions. Review of SQL Slide 34 of 46

35 Explicit Transactions 1 The foreign key which references the Department relation is made deferrable and then deferred. CREATE TABLE instructor ( < column declarations > < constraints other than fkey_instr >); CREATE TABLE department ( < column declarations > < constraints >); ALTER TABLE instructor ADD CONSTRAINT fkey_instr FOREIGN KEY ( dept_name ) REFERENCES department ( dept_name ) DEFERRABLE INITIALLY DEFERRED ; This means that it is not checked until the end of a transaction. Notes: The constraint fkey instr is added using ALTER TABLE instructor after the CREATE TABLE Department directive to avoid forward-reference errors during table definition. The constraint fkey instr is made DEFERRABLE and set to be INITIALLY DEFERRED to allow transactions to defer checking it until commit time during update execution. Review of SQL Slide 35 of 46

36 Explicit Transactions 2 In both PostgreSQL and MySQL BEGIN and COMMIT markers may be used to identify the bounds of the transaction. BEGIN ; INSERT INTO instructor VALUES ( 00000, Ortega, Management, ); INSERT INTO department VALUES ( Management, Watson, , ); COMMIT ; Note: If the constraint fkey instr already exists but is not DEFERRABLE or is DEFERRABLE but not INITIALLY DEFERRED, this may be changed by dropping the constraint and then adding it again with the desired properties. ALTER TABLE instructor DROP CONSTRAINT fkey_instr ; ALTER TABLE instructor ADD CONSTRAINT fkey_instr FOREIGN KEY ( dept_name ) REFERENCES department ( dept_name ) DEFERRABLE INITIALLY DEFERRED ; Review of SQL Slide 36 of 46

37 Cascading Updates By default, if an update would violate an integrity constraint, that update fails and the database is not changed. However, it is possible to cascade DELETE and UPDATE directives with respect to foreign-key constraints. Example: Suppose that a course is dropped (is deleted from the course relation.) It then makes sense to delete all information about the sections of that course as well. This is accomplished via the ON DELETE CASCADE clause: CREATE TABLE section ( course_id VARCHAR (8),... FOREIGN KEY ( course_id ) REFERENCES course ON DELETE CASCADE ); Review of SQL Slide 37 of 46

38 Cascading Updates 2 Cascading may also be applied to UPDATE (modification) directives. Example: Suppose that the bureaucrats decide to change the course IDs. It then makes sense to reflect those changes in the other relations which have that attribute as a foreign key from the course relation. This may be accomplished via the ON UPDATE CASCADE clause: CREATE TABLE section ( course_id VARCHAR (8),... FOREIGN KEY ( course_id ) REFERENCES course ON DELETE CASCADE ON UPDATE CASCADE ); Review of SQL Slide 38 of 46

39 Cascading Updates 3 Upon deletion of a foreign key, conversion to null is sometimes the appropriate step. Example: Suppose that the advisor of a student leaves the university. It then makes sense to keep the student in the advisor relation, but to give the student a null advisor. This may be accomplished via the ON UPDATE SET NULL clause: CREATE TABLE advisor ( s_id VARCHAR (5), i_id VARCHAR (5), PRIMARY KEY ( s_id ), FOREIGN KEY ( i_id ) REFERENCES INSTRUCTOR ( ID) ON DELETE SET NULL, FOREIGN KEY ( s_id ) REFERENCES STUDENT ( ID) ON DELETE CASCADE ); Review of SQL Slide 39 of 46

40 A Schema for a Grading Database Shown below are SQL definitions for two of the relations for a grading database similar to that used for this course. CREATE TABLE Student ( Name VARCHAR (40) Not Null, Personnr CHAR (11) Not Null, -- YYMMDD - XXXX Ident VARCHAR (10) Not Null, umu. se user ID PRIMARY KEY ( Ident ), UNIQUE ( Personnr ) ); CREATE TABLE ObligEx ( Ident VARCHAR (10) Not Null, Number INTEGER Not Null, -- exercise number (1 or 2) Grade INTEGER, -- numerical point score HandedIn DATE, -- date first submitted Graded DATE, -- date first graded Approved DATE, -- date approved satisfactory Status CHAR (1), -- S or U PRIMARY KEY ( Ident, Number ), CONSTRAINT obligex_ident_fkey FOREIGN KEY ( Ident ) REFERENCES Student ( Ident ) ON UPDATE CASCADE ); Student Ident PersonNr Name ObligEx Ident Number Grade HandedIn Graded Approved Status Review of SQL Slide 40 of 46

41 Outer Joins First want a scheme with the form of ObligEx, for Exercise 1 only, with an entry for every student and nulls for missing values. The (left) outer join operation delivers the desired structure. It is similar to an (inner) join, but it fills in missing matches with nulls. It is called left because the left table in the construction is the base; the right table is padded with nulls. SELECT S. Ident, E1.Grade, E1. HandedIn, E1.Graded, E1. Approved, E1. Status FROM ( SELECT Ident FROM Student ) AS S LEFT OUTER JOIN ( SELECT * FROM ObligEx WHERE Number =1) AS E1 ON (S. Ident =E1. Ident ); A right outer join is defined analogously. Review of SQL Slide 41 of 46

42 Outer Joins 2 Now add on the second exercise as well by using a second outer join. ObligExAll Ident Gr1 DateH1 DateG1 DateA1 St1 Gr2 DateH2 DateG2 DateA2 St2 SELECT S. Ident, E1. Grade AS Gr1, E1. HandedIn AS DateH1, E1. Graded AS DateG1, E1. Approved AS DateA1, E1. Status St1, E2. Grade AS Gr2, E2. HandedIn AS DateH2, E2. Graded AS DateG2, E2. Approved AS DateA2, E2. Status AS St2 FROM ( SELECT Ident FROM Student ) AS S LEFT OUTER JOIN ( SELECT * FROM ObligEx WHERE Number =1) AS E1 ON (S. Ident =E1. Ident ) LEFT OUTER JOIN ( SELECT * FROM ObligEx WHERE Number =2) AS E2 ON (S. Ident =E2. Ident ); Review of SQL Slide 42 of 46

43 Views A view is a virtual table which is constructed using a query. It differs from a query in that: It persists in time, just as a true table. Its state reflects updates to the true tables. It has a name and may be used in large part as would any table of the database. Basic syntax: CREATE VIEW <name> AS <query>; Example: CREATE VIEW Instructor_Student ( Instr_ID, Instr_name, Student_ID, Student_name ) AS SELECT DISTINCT I.ID, I.name, S.ID, S. name AS I INNER JOIN teaches AS Te ON ( I. ID = Te. ID) INNER JOIN takes as Ta ON (( Te. course_id =Ta. course_id ) AND (Te. sec_id =Ta. sec_id ) AND (Te. semester =Ta. semester ) AND (Te. year =Ta. year )) INNER JOIN student as S ON (S.ID=Ta.ID ); Review of SQL Slide 43 of 46

44 Updates to Views Under limited conditions, updates to views are possible in standard SQL. There must be an obvious way to reflect the update to the true tables. Unfortunately, PostgreSQL does not support updates to views natively. It is, however, possible to use triggers to accomplish view updates in PostgreSQL 9.x. Review of SQL Slide 44 of 46

45 The Logic of Null Values The value of NULL is treated as unknown in truth-valued expressions. A B (A OR B) (A AND B) (NOT A) false false false false false false true true false true true false true false false true true true true false true unknown true unknown false false unknown unknown false true unknown true true unknown unknown unknown false unknown false unknown unknown unknown unknown unknown unknown Conditions of the form (A=B) also evaluate to unknown when at least one of the arguments evaluates to NULL. Expressions which evaluate to unknown are not considered to be true for the purpose of a query in SQL. Review of SQL Slide 45 of 46

46 Aggregation Question: What about basic aggregation in SQL? Answer: It will be reviewed with the material on OLAP and more advanced aggregation. Review of SQL Slide 46 of 46

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries COMP 5138 Relational Database Management Systems Week 5 : Basic COMP5138 "Relational Database Managment Systems" J. Davis 2006 5-1 Today s Agenda Overview Basic Queries Joins Queries Aggregate Functions

More information

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

More information

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL: C H A P T E R4 Intermediate SQL Practice Exercises 4.1 Write the following queries in SQL: a. Display a list of all instructors, showing their ID, name, and the number of sections that they have taught.

More information

SQL NULL s, Constraints, Triggers

SQL NULL s, Constraints, Triggers CS145 Lecture Notes #9 SQL NULL s, Constraints, Triggers Example schema: CREATE TABLE Student (SID INTEGER PRIMARY KEY, name CHAR(30), age INTEGER, GPA FLOAT); CREATE TABLE Take (SID INTEGER, CID CHAR(10),

More information

CPS352 Database Systems: Design Project

CPS352 Database Systems: Design Project CPS352 Database Systems: Design Project Purpose: Due: To give you experience with designing and implementing a database to model a real domain Various milestones due as shown in the syllabus Requirements

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.

More information

Information Systems SQL. Nikolaj Popov

Information Systems SQL. Nikolaj Popov Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria popov@risc.uni-linz.ac.at Outline SQL Table Creation Populating and Modifying

More information

Introduction to SQL (3.1-3.4)

Introduction to SQL (3.1-3.4) CSL 451 Introduction to Database Systems Introduction to SQL (3.1-3.4) Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Summary Parts

More information

A Brief Introduction to MySQL

A Brief Introduction to MySQL A Brief Introduction to MySQL by Derek Schuurman Introduction to Databases A database is a structured collection of logically related data. One common type of database is the relational database, a term

More information

Database Administration with MySQL

Database Administration with MySQL Database Administration with MySQL Suitable For: Database administrators and system administrators who need to manage MySQL based services. Prerequisites: Practical knowledge of SQL Some knowledge of relational

More information

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX ISSN: 2393-8528 Contents lists available at www.ijicse.in International Journal of Innovative Computer Science & Engineering Volume 3 Issue 2; March-April-2016; Page No. 09-13 A Comparison of Database

More information

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems CSC 74 Database Management Systems Topic #0: SQL Part A: Data Definition Language (DDL) Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning Schema and Catalog Schema A collection

More information

Exercise 1: Relational Model

Exercise 1: Relational Model Exercise 1: Relational Model 1. Consider the relational database of next relational schema with 3 relations. What are the best possible primary keys in each relation? employ(person_name, street, city)

More information

Instant SQL Programming

Instant SQL Programming Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions

More information

How To Create A Table In Sql 2.5.2.2 (Ahem)

How To Create A Table In Sql 2.5.2.2 (Ahem) Database Systems Unit 5 Database Implementation: SQL Data Definition Language Learning Goals In this unit you will learn how to transfer a logical data model into a physical database, how to extend or

More information

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1 Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1 A feature of Oracle Rdb By Ian Smith Oracle Rdb Relational Technology Group Oracle Corporation 1 Oracle Rdb Journal SQL:1999 and Oracle Rdb V7.1 The

More information

www.gr8ambitionz.com

www.gr8ambitionz.com Data Base Management Systems (DBMS) Study Material (Objective Type questions with Answers) Shared by Akhil Arora Powered by www. your A to Z competitive exam guide Database Objective type questions Q.1

More information

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Relational Database Languages Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Domain relational calculus QBE (used in Access) History of SQL Standards:

More information

Relational Databases

Relational Databases Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 18 Relational data model Domain domain: predefined set of atomic values: integers, strings,... every attribute

More information

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff D80198GC10 Oracle Database 12c SQL and Fundamentals Summary Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff Level Professional Delivery Method Instructor-led

More information

IT2305 Database Systems I (Compulsory)

IT2305 Database Systems I (Compulsory) Database Systems I (Compulsory) INTRODUCTION This is one of the 4 modules designed for Semester 2 of Bachelor of Information Technology Degree program. CREDITS: 04 LEARNING OUTCOMES On completion of this

More information

Advance DBMS. Structured Query Language (SQL)

Advance DBMS. Structured Query Language (SQL) Structured Query Language (SQL) Introduction Commercial database systems use more user friendly language to specify the queries. SQL is the most influential commercially marketed product language. Other

More information

SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6

SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6 SUBQUERIES AND VIEWS CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6 String Comparisons and GROUP BY 2! Last time, introduced many advanced features of SQL, including GROUP BY! Recall:

More information

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks] EXAMINATIONS 2005 MID-YEAR COMP 302 Database Systems Time allowed: Instructions: 3 Hours Answer all questions. Make sure that your answers are clear and to the point. Write your answers in the spaces provided.

More information

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically Normalization of databases Database normalization is a technique of organizing the data in the database. Normalization is a systematic approach of decomposing tables to eliminate data redundancy and undesirable

More information

Introduction to Microsoft Jet SQL

Introduction to Microsoft Jet SQL Introduction to Microsoft Jet SQL Microsoft Jet SQL is a relational database language based on the SQL 1989 standard of the American Standards Institute (ANSI). Microsoft Jet SQL contains two kinds of

More information

CSC 443 Data Base Management Systems. Basic SQL

CSC 443 Data Base Management Systems. Basic SQL CSC 443 Data Base Management Systems Lecture 6 SQL As A Data Definition Language Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along

More information

Using Temporary Tables to Improve Performance for SQL Data Services

Using Temporary Tables to Improve Performance for SQL Data Services Using Temporary Tables to Improve Performance for SQL Data Services 2014- Informatica Corporation. No part of this document may be reproduced or transmitted in any form, by any means (electronic, photocopying,

More information

Oracle Database 11g SQL

Oracle Database 11g SQL AO3 - Version: 2 19 June 2016 Oracle Database 11g SQL Oracle Database 11g SQL AO3 - Version: 2 3 days Course Description: This course provides the essential SQL skills that allow developers to write queries

More information

Oracle SQL. Course Summary. Duration. Objectives

Oracle SQL. Course Summary. Duration. Objectives Oracle SQL Course Summary Identify the major structural components of the Oracle Database 11g Create reports of aggregated data Write SELECT statements that include queries Retrieve row and column data

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle University Contact Us: + 38516306373 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the

More information

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added? DBMS Questions 1.) Which type of file is part of the Oracle database? A.) B.) C.) D.) Control file Password file Parameter files Archived log files 2.) Which statements are use to UNLOCK the user? A.)

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: +966 12 739 894 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training is designed to

More information

Netezza SQL Class Outline

Netezza SQL Class Outline Netezza SQL Class Outline CoffingDW education has been customized for every customer for the past 20 years. Our classes can be taught either on site or remotely via the internet. Education Contact: John

More information

SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach TRAINING & REFERENCE murach's SQL Server 2012 for developers Bryan Syverson Joel Murach Mike Murach & Associates, Inc. 4340 N. Knoll Ave. Fresno, CA 93722 www.murach.com murachbooks@murach.com Expanded

More information

Oracle Database 12c: Introduction to SQL Ed 1.1

Oracle Database 12c: Introduction to SQL Ed 1.1 Oracle University Contact Us: 1.800.529.0165 Oracle Database 12c: Introduction to SQL Ed 1.1 Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,

More information

IT2304: Database Systems 1 (DBS 1)

IT2304: Database Systems 1 (DBS 1) : Database Systems 1 (DBS 1) (Compulsory) 1. OUTLINE OF SYLLABUS Topic Minimum number of hours Introduction to DBMS 07 Relational Data Model 03 Data manipulation using Relational Algebra 06 Data manipulation

More information

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database

More information

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Chapter 1: Introduction. Database Management System (DBMS) University Database Example This image cannot currently be displayed. Chapter 1: Introduction Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Database Management System (DBMS) DBMS contains information

More information

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013 CSE 530A Database Management Systems Introduction Washington University Fall 2013 Overview Time: Mon/Wed 7:00-8:30 PM Location: Crow 206 Instructor: Michael Plezbert TA: Gene Lee Websites: http://classes.engineering.wustl.edu/cse530/

More information

Define terms Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins

Define terms Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins Chapter 7 Advanced SQL 1 Define terms Objectives Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins 2 Nested Queries (Subqueries)

More information

MOC 20461C: Querying Microsoft SQL Server. Course Overview

MOC 20461C: Querying Microsoft SQL Server. Course Overview MOC 20461C: Querying Microsoft SQL Server Course Overview This course provides students with the knowledge and skills to query Microsoft SQL Server. Students will learn about T-SQL querying, SQL Server

More information

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com Essential SQL 2 Essential SQL This bonus chapter is provided with Mastering Delphi 6. It is a basic introduction to SQL to accompany Chapter 14, Client/Server Programming. RDBMS packages are generally

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

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to: D61830GC30 for Developers Summary Duration Vendor Audience 5 Days Oracle Database Administrators, Developers, Web Administrators Level Technology Professional Oracle 5.6 Delivery Method Instructor-led

More information

Oracle 10g PL/SQL Training

Oracle 10g PL/SQL Training Oracle 10g PL/SQL Training Course Number: ORCL PS01 Length: 3 Day(s) Certification Exam This course will help you prepare for the following exams: 1Z0 042 1Z0 043 Course Overview PL/SQL is Oracle's Procedural

More information

Querying Microsoft SQL Server 2012

Querying Microsoft SQL Server 2012 Querying Microsoft SQL Server 2012 MOC 10774 About this Course This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL

More information

MySQL for Beginners Ed 3

MySQL for Beginners Ed 3 Oracle University Contact Us: 1.800.529.0165 MySQL for Beginners Ed 3 Duration: 4 Days What you will learn The MySQL for Beginners course helps you learn about the world's most popular open source database.

More information

Database Design and the E-R Model

Database Design and the E-R Model C H A P T E R 7 Database Design and the E-R Model Practice Exercises 7.1 Answer: The E-R diagram is shown in Figure 7.1. Payments are modeled as weak entities since they are related to a specific policy.

More information

Introduction to Querying & Reporting with SQL Server

Introduction to Querying & Reporting with SQL Server 1800 ULEARN (853 276) www.ddls.com.au Introduction to Querying & Reporting with SQL Server Length 5 days Price $4169.00 (inc GST) Overview This five-day instructor led course provides students with the

More information

Programming with SQL

Programming with SQL Unit 43: Programming with SQL Learning Outcomes A candidate following a programme of learning leading to this unit will be able to: Create queries to retrieve information from relational databases using

More information

A basic create statement for a simple student table would look like the following.

A basic create statement for a simple student table would look like the following. Creating Tables A basic create statement for a simple student table would look like the following. create table Student (SID varchar(10), FirstName varchar(30), LastName varchar(30), EmailAddress varchar(30));

More information

1 Structured Query Language: Again. 2 Joining Tables

1 Structured Query Language: Again. 2 Joining Tables 1 Structured Query Language: Again So far we ve only seen the basic features of SQL. More often than not, you can get away with just using the basic SELECT, INSERT, UPDATE, or DELETE statements. Sometimes

More information

SQL Tables, Keys, Views, Indexes

SQL Tables, Keys, Views, Indexes CS145 Lecture Notes #8 SQL Tables, Keys, Views, Indexes Creating & Dropping Tables Basic syntax: CREATE TABLE ( DROP TABLE ;,,..., ); Types available: INT or INTEGER REAL or FLOAT CHAR( ), VARCHAR( ) DATE,

More information

Querying Microsoft SQL Server (20461) H8N61S

Querying Microsoft SQL Server (20461) H8N61S HP Education Services course data sheet Querying Microsoft SQL Server (20461) H8N61S Course Overview In this course, you will learn the technical skills required to write basic Transact-SQL (T-SQL) queries

More information

Chapter 5. SQL: Queries, Constraints, Triggers

Chapter 5. SQL: Queries, Constraints, Triggers Chapter 5 SQL: Queries, Constraints, Triggers 1 Overview: aspects of SQL DML: Data Management Language. Pose queries (Ch. 5) and insert, delete, modify rows (Ch. 3) DDL: Data Definition Language. Creation,

More information

ICAB4136B Use structured query language to create database structures and manipulate data

ICAB4136B Use structured query language to create database structures and manipulate data ICAB4136B Use structured query language to create database structures and manipulate data Release: 1 ICAB4136B Use structured query language to create database structures and manipulate data Modification

More information

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY Discovering SQL A HANDS-ON GUIDE FOR BEGINNERS Alex Kriegel WILEY Wiley Publishing, Inc. INTRODUCTION xxv CHAPTER 1: DROWNING IN DATA, DYING OF THIRST FOR KNOWLEDGE 1 Data Deluge and Informational Overload

More information

UNIT 6. Structured Query Language (SQL) Text: Chapter 5

UNIT 6. Structured Query Language (SQL) Text: Chapter 5 UNIT 6 Structured Query Language (SQL) Text: Chapter 5 Learning Goals Given a database (a set of tables ) you will be able to express a query in SQL, involving set operators, subqueries and aggregations

More information

Oracle Database 10g Express

Oracle Database 10g Express Oracle Database 10g Express This tutorial prepares the Oracle Database 10g Express Edition Developer to perform common development and administrative tasks of Oracle Database 10g Express Edition. Objectives

More information

Week 4 & 5: SQL. SQL as a Query Language

Week 4 & 5: SQL. SQL as a Query Language Week 4 & 5: SQL The SQL Query Language Select Statements Joins, Aggregate and Nested Queries Insertions, Deletions and Updates Assertions, Views, Triggers and Access Control SQL 1 SQL as a Query Language

More information

EECS 647: Introduction to Database Systems

EECS 647: Introduction to Database Systems EECS 647: Introduction to Database Systems Instructor: Luke Huan Spring 2013 Administrative Take home background survey is due this coming Friday The grader of this course is Ms. Xiaoli Li and her email

More information

SQL. Short introduction

SQL. Short introduction SQL Short introduction 1 Overview SQL, which stands for Structured Query Language, is used to communicate with a database. Through SQL one can create, manipulate, query and delete tables and contents.

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-97 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals

More information

Structured Query Language (SQL)

Structured Query Language (SQL) Objectives of SQL Structured Query Language (SQL) o Ideally, database language should allow user to: create the database and relation structures; perform insertion, modification, deletion of data from

More information

Database Query 1: SQL Basics

Database Query 1: SQL Basics Database Query 1: SQL Basics CIS 3730 Designing and Managing Data J.G. Zheng Fall 2010 1 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic

More information

Relational Database: Additional Operations on Relations; SQL

Relational Database: Additional Operations on Relations; SQL Relational Database: Additional Operations on Relations; SQL Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin Overview The course packet

More information

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan More on SQL Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan SELECT A1, A2,, Am FROM R1, R2,, Rn WHERE C1, C2,, Ck Interpreting a Query

More information

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

Database 10g Edition: All possible 10g features, either bundled or available at additional cost. Concepts Oracle Corporation offers a wide variety of products. The Oracle Database 10g, the product this exam focuses on, is the centerpiece of the Oracle product set. The "g" in "10g" stands for the Grid

More information

The Relational Model. Why Study the Relational Model?

The Relational Model. Why Study the Relational Model? The Relational Model Chapter 3 Instructor: Vladimir Zadorozhny vladimir@sis.pitt.edu Information Science Program School of Information Sciences, University of Pittsburgh 1 Why Study the Relational Model?

More information

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours Course 20461C: Querying Microsoft SQL Server Duration: 35 hours About this Course This course is the foundation for all SQL Server-related disciplines; namely, Database Administration, Database Development

More information

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

More information

Databases 2011 The Relational Model and SQL

Databases 2011 The Relational Model and SQL Databases 2011 Christian S. Jensen Computer Science, Aarhus University What is a Database? Main Entry: da ta base Pronunciation: \ˈdā-tə-ˌbās, ˈda- also ˈdä-\ Function: noun Date: circa 1962 : a usually

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training teaches you how to write subqueries,

More information

Relational Databases and SQLite

Relational Databases and SQLite Relational Databases and SQLite Charles Severance Python for Informatics: Exploring Information www.pythonlearn.com SQLite Browser http://sqlitebrowser.org/ Relational Databases Relational databases model

More information

4. SQL. Contents. Example Database. CUSTOMERS(FName, LName, CAddress, Account) PRODUCTS(Prodname, Category) SUPPLIERS(SName, SAddress, Chain)

4. SQL. Contents. Example Database. CUSTOMERS(FName, LName, CAddress, Account) PRODUCTS(Prodname, Category) SUPPLIERS(SName, SAddress, Chain) ECS-165A WQ 11 66 4. SQL Contents Basic Queries in SQL (select statement) Set Operations on Relations Nested Queries Null Values Aggregate Functions and Grouping Data Definition Language Constructs Insert,

More information

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

SQL - QUICK GUIDE. Allows users to access data in relational database management systems. http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating

More information

Comp 5311 Database Management Systems. 3. Structured Query Language 1

Comp 5311 Database Management Systems. 3. Structured Query Language 1 Comp 5311 Database Management Systems 3. Structured Query Language 1 1 Aspects of SQL Most common Query Language used in all commercial systems Discussion is based on the SQL92 Standard. Commercial products

More information

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT CSI 2132 Lab 3 More on SQL 1 Outline Destroying and Altering Relations DROP TABLE ALTER TABLE SELECT Exercise: Inserting more data into previous tables Single-table queries Multiple-table queries 2 1 Destroying

More information

Databases in Engineering / Lab-1 (MS-Access/SQL)

Databases in Engineering / Lab-1 (MS-Access/SQL) COVER PAGE Databases in Engineering / Lab-1 (MS-Access/SQL) ITU - Geomatics 2014 2015 Fall 1 Table of Contents COVER PAGE... 0 1. INTRODUCTION... 3 1.1 Fundamentals... 3 1.2 How To Create a Database File

More information

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS Can Türker Swiss Federal Institute of Technology (ETH) Zurich Institute of Information Systems, ETH Zentrum CH 8092 Zurich, Switzerland

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: +381 11 2016811 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn Understanding the basic concepts of relational databases ensure refined code by developers.

More information

DbSchema Tutorial with Introduction in SQL Databases

DbSchema Tutorial with Introduction in SQL Databases DbSchema Tutorial with Introduction in SQL Databases Contents Connect to the Database and Create First Tables... 2 Create Foreign Keys... 7 Create Indexes... 9 Generate Random Data... 11 Relational Data

More information

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL Chapter 9 Joining Data from Multiple Tables Oracle 10g: SQL Objectives Identify a Cartesian join Create an equality join using the WHERE clause Create an equality join using the JOIN keyword Create a non-equality

More information

RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague

RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague course: Database Applications (NDBI026) WS2015/16 RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague student duties final DB

More information

6 CHAPTER. Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following:

6 CHAPTER. Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following: 6 CHAPTER Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following: The history of relational database systems and SQL How the three-level architecture

More information

3. Relational Model and Relational Algebra

3. Relational Model and Relational Algebra ECS-165A WQ 11 36 3. Relational Model and Relational Algebra Contents Fundamental Concepts of the Relational Model Integrity Constraints Translation ER schema Relational Database Schema Relational Algebra

More information

CS143 Notes: Views & Authorization

CS143 Notes: Views & Authorization CS143 Notes: Views & Authorization Book Chapters (4th) Chapter 4.7, 6.5-6 (5th) Chapter 4.2, 8.6 (6th) Chapter 4.4, 5.3 Views What is a view? A virtual table created on top of other real tables Almost

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Introduction to SQL training

More information

Course ID#: 1401-801-14-W 35 Hrs. Course Content

Course ID#: 1401-801-14-W 35 Hrs. Course Content Course Content Course Description: This 5-day instructor led course provides students with the technical skills required to write basic Transact- SQL queries for Microsoft SQL Server 2014. This course

More information

Lab 2: PostgreSQL Tutorial II: Command Line

Lab 2: PostgreSQL Tutorial II: Command Line Lab 2: PostgreSQL Tutorial II: Command Line In the lab 1, we learned how to use PostgreSQL through the graphic interface, pgadmin. However, PostgreSQL may not be used through a graphical interface. This

More information

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Structured Query Language HANS- PETTER HALVORSEN, 2014.03.03 Faculty of Technology, Postboks 203,

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server Course 20461C: Querying Microsoft SQL Server Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions, tools used

More information

Querying Microsoft SQL Server 20461C; 5 days

Querying Microsoft SQL Server 20461C; 5 days Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc Querying Microsoft SQL Server 20461C; 5 days Course Description This 5-day

More information

1. SELECT DISTINCT f.fname FROM Faculty f, Class c WHERE f.fid = c.fid AND c.room = LWSN1106

1. SELECT DISTINCT f.fname FROM Faculty f, Class c WHERE f.fid = c.fid AND c.room = LWSN1106 Database schema: Department(deptid, dname, location) Student(snum, sname, deptid, slevel, age) Faculty(fid, fname, deptid) Class(cname, time, room, fid) Enrolled(snum, cname) SQL queries: 1. Get the names

More information

DBMS / Business Intelligence, SQL Server

DBMS / Business Intelligence, SQL Server DBMS / Business Intelligence, SQL Server Orsys, with 30 years of experience, is providing high quality, independant State of the Art seminars and hands-on courses corresponding to the needs of IT professionals.

More information

Boats bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red. Figure 1: Instances of Sailors, Boats and Reserves

Boats bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red. Figure 1: Instances of Sailors, Boats and Reserves Tutorial 5: SQL By Chaofa Gao Tables used in this note: Sailors(sid: integer, sname: string, rating: integer, age: real); Boats(bid: integer, bname: string, color: string); Reserves(sid: integer, bid:

More information

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model CS2Bh: Current Technologies Introduction to XML and Relational Databases Spring 2005 The Relational Model CS2 Spring 2005 (LN6) 1 The relational model Proposed by Codd in 1970. It is the dominant data

More information

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7 SQL DATA DEFINITION: KEY CONSTRAINTS CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7 Data Definition 2 Covered most of SQL data manipulation operations Continue exploration of SQL

More information