Introduction to SQL (3.1-3.4)

Similar documents
You can use command show database; to check if bank has been created.

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

Advance DBMS. Structured Query Language (SQL)

Chapter 6: Integrity Constraints

Simple SQL Queries (3)

Exercise 1: Relational Model

Comp 3311 Database Management Systems. 2. Relational Model Exercises

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

Introduction to SQL C H A P T E R3. Exercises

SQL is capable in manipulating relational data SQL is not good for many other tasks

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

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

Chapter 1: Introduction. Database Management System (DBMS)

Introduction to database management systems

Relationele Databases 2002/2003

Lab Manual. Database Systems COT-313 & Database Management Systems Lab IT-216

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

Boyce-Codd Normal Form

Figure 4.12.Insurancedatabase.

Chapter 4: SQL. Schema Used in Examples

Chapter 1: Introduction

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

Lesson 8: Introduction to Databases E-R Data Modeling

Exercises. a. Find the total number of people who owned cars that were involved in accidents

Chapter 7: Relational Database Design

B2.2-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

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

Basic Concepts. Chapter A: Network Model. Cont.) Data-Structure Diagrams (Cont( Data-Structure Diagrams. General Relationships. The DBTG CODASYL Model

New York University Computer Science Department Courant Institute of Mathematical Sciences


Chapter 1: Introduction

How To Create A Table In Sql (Ahem)

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Chapter 6: Integrity and Security. Domain Constraints

Chapter 2: Entity-Relationship Model. E-R R Diagrams

Programming with SQL

Oracle Database 10g: Introduction to SQL

CSC 443 Data Base Management Systems. Basic SQL

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Chapter 7: Relational Database Design

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

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

Databases What the Specification Says

Oracle Database 10g Express

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Functional Dependencies

Evaluation of Expressions

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

IT2304: Database Systems 1 (DBS 1)

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

CSE 132A. Database Systems Principles

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

IT2305 Database Systems I (Compulsory)

There are five fields or columns, with names and types as shown above.

Database Query 1: SQL Basics

Instant SQL Programming

CSE 233. Database System Overview

A Brief Introduction to MySQL

Data Models and Database Management Systems (DBMSs) Dr. Philip Cannata

Relationele Databases 2002/2003

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

CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES

4 Simple Database Features

Chapter 4: SQL. Schema Used in Examples. Basic Structure. The select Clause. modifications and enhancements! A typical SQL query has the form:


Faculty of Engineering and Architecture. Computer Engineering Department DATABASE MANAGEMENT SYSTEMS POSTLAB #3 SOLUTION

The Relational Model. Why Study the Relational Model?

TYPICAL QUESTIONS & ANSWERS

Summary on Chapter 4 Basic SQL

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

Chapter 2: Entity-Relationship Model

SQL. Short introduction

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

Converting E-R Diagrams to Relational Model. Winter Lecture 17

Oracle SQL. Course Summary. Duration. Objectives

Examine the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER Primary Key FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25)

EECS 647: Introduction to Database Systems

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

CSC 443 Fall 2011 Dr. R. M. Siegfried. Answers to Assignment #1

Information Systems SQL. Nikolaj Popov

Oracle 10g PL/SQL Training

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Part 4: Database Language - SQL

Oracle Database 11g SQL

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

DATABASE SECURITY, INTEGRITY AND RECOVERY

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

Chapter 14: Query Optimization

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

Netezza SQL Class Outline

Foundations of Information Management

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

1 Structured Query Language: Again. 2 Joining Tables

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

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

Using Temporary Tables to Improve Performance for SQL Data Services

Introduction to Databases

Transcription:

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 of SQL Language Data-definition language Data-manipulation language SQL Data Definition Basic data types Difference between char and varchar Schema definition Primary key Foreign key Referential integrity constraint not null constraint create, insert, alter, drop and delete 2!

Summary SQL Query Structure SELECT clause all and distinct Attribute specification * FROM clause WHERE clause Logical connectives and, or and not Comparison operators between and not between Order of processing the clauses Natural Join Rename operator as Correlation name String Operations Special characters % and _ like Case sensitivity upper and lower trim Ordering the display of tuples order by, asc, and desc 3!

3.1.a Find the titles of courses in the Comp. Sci. department that have 3 credits 4!

3.1.b Find the IDs of all students who were taught by an instructor named Einstein; make sure there are no duplicates in the result. 5!

3.6 Write a query that finds departments whose names contain the string sci as a substring, regardless of the case. 6!

3.6 Find all students with names starting in m and taking courses offered by Comp. Sci. department 7!

3.7 Consider the SQL query select distinct p.a1 from p, r1, r2 where p.a1=r1.a1 or p.a1=r2.a1 Under what conditions does the preceding query select values of p.a1 that are either in r1 or in r2? 8!

3.8.b Find the names of all customers who live on the same street and the same city as Smith branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) loan(loan_number, branch_name, amount) borrower (customer_name, loan_number) account (account_number, branch_name, balance) depositor (customer_name, account_number) 9!

3.8.c Find the names of all branches with customers who have an account in the bank and who live in Harrison branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) loan(loan_number, branch_name, amount) borrower (customer_name, loan_number) account (account_number, branch_name, balance) depositor (customer_name, account_number) 10!

3.9.a Find the names and cities of residence of all employees who work for First Bank Corporation employee (employee_name, street, city) works (employee_name, company_name, salary) company (company_name, city) manages (employee_name, manager_name) 11!

3.9.b Find the names and cities of residence of all employees who work for First Bank Corporation and earn more than $10,000 employee (employee_name, street, city) works (employee_name, company_name, salary) company (company_name, city) manages (employee_name, manager_name) 12!

3.9.c Find all employees in the database who do not work for First Bank Corporation employee (employee_name, street, city) works (employee_name, company_name, salary) company (company_name, city) manages (employee_name, manager_name) 13!

3.16.b Find all employees in the database who live in the same cities for which they work employee (employee_name, street, city) works (employee_name, company_name, salary) company (company_name, city) manages (employee_name, manager_name) 14!

3.16.c Find all employees in the database who live in the same cities and on the same streets as do their managers employee (employee_name, street, city) works (employee_name, company_name, salary) company (company_name, city) manages (employee_name, manager_name) 15!

3.13 Write the SQL DDL corresponding to the following schema person (driver id, name, address) car (license, model, year) accident (report number, date, location) owns (driver id, license) participated (report number, license, driver id, damage_amount) 16!

3.14 Find all the accident related information involving cars belonging to John Smith person (driver id, name, address) car (license, model, year) accident (report number, date, location) owns (driver id, license) participated (report number, license, driver id, damage_amount) 17!

Find all the car models that were involved in an accident in the year 2009. person (driver id, name, address) car (license, model, year) accident (report number, date, location) owns (driver id, license) participated (report number, license, driver id, damage_amount) 18!

EN 4.1 Why does SQL allow duplicate tuples in a table or in a query result? 19!

EN 4.8 Write appropriate SQL DDL statements for the following LIBRARY database 20!