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

Similar documents
Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

RETRIEVING DATA USING THE SQL SELECT STATEMENT

Oracle Database SQL Basics

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions

Oracle Syllabus Course code-r10605 SQL

Intermediate SQL: Aggregated Data, Joins and Set Operators

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

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

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Subquery: There are basically three types of subqueries are:

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

CSC Web Programming. Introduction to SQL

Aggregate Functions. Eng. Mohammed Alokshiya. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Dept. Database Lab (ECOM 4113)

Oracle Database 11g: SQL and PL/SQL Fundamentals

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

Join, Sub queries and set operators

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

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Introduction. Sample Database SQL-92. Sample Data. Sample Data. Chapter 6 Introduction to Structured Query Language (SQL)

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Full file at

Sun Certified MySQL Associate

Querying Data with Transact SQL

Database Programming with SQL

KORA. RDBMS Concepts II

Oracle Database 10g: Introduction to SQL

5. Single-row function

Oracle Database: SQL and PL/SQL Fundamentals NEW

Lab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama

1) Introduction to SQL

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

T-SQL Training: T-SQL for SQL Server for Developers

@vmahawar. Agenda Topics Quiz Useful Links

Data Manipulation Language (DML)

SQL. Char (30) can store ram, ramji007 or 80- b

Manipulating Data. Copyright 2004, Oracle. All rights reserved.

Based on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO

SQL functions fit into two broad categories: Data definition language Data manipulation language

Introduction to Oracle9i: SQL

Database design process

Course Outline and Objectives: Database Programming with SQL

Test Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke

Relational Database Language

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

Introduction to Computer Science and Business

Database Management Systems,

SQL Data Manipulation Language. Lecture 5. Introduction to SQL language. Last updated: December 10, 2014

UNIT-IV (Relational Database Language, PL/SQL)

SQL Interview Questions

Creating Other Schema Objects

Creating and Managing Tables Schedule: Timing Topic

An Introduction to Structured Query Language

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Database Technology. Topic 3: SQL. Olaf Hartig.

An Introduction to Structured Query Language

An Introduction to Structured Query Language

Reporting Aggregated Data Using the Group Functions. Copyright 2004, Oracle. All rights reserved.

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014

2) SQL includes a data definition language, a data manipulation language, and SQL/Persistent stored modules. Answer: TRUE Diff: 2 Page Ref: 36

1Z0-007 ineroduction to oracle9l:sql

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH

Database Foundations. 6-9 Joining Tables Using JOIN. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

SQL STRUCTURED QUERY LANGUAGE

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

Querying Data with Transact-SQL

An Introduction to Structured Query Language

An Introduction to Structured Query Language

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved.

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

Study Guide for: Oracle Database SQL Certified Expert Exam Guide (Exam 1Z0-047)

Data Manipulation Language

SQL. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior

20461: Querying Microsoft SQL Server 2014 Databases

Exam: 1Z Title : Introduction to Oracle9i: SQL. Ver :

Oracle Database: Introduction to SQL Ed 2

Introduction to the Structured Query Language [ SQL ] (Significant Concepts)

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

Unit Assessment Guide

Data about data is database Select correct option: True False Partially True None of the Above

20761 Querying Data with Transact SQL

Unit 1 - Chapter 4,5

Chapter 3: Introduction to SQL

20461: Querying Microsoft SQL Server

Lecture 6 - More SQL

Intermediate SQL ( )

Exam code: Exam name: Database Fundamentals. Version 16.0

Chapter 3: Introduction to SQL

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

MTA Database Administrator Fundamentals Course

Sql Server Syllabus. Overview

Transcription:

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 Data 8 Aggregating Data using Group Functions 9 SubQueries

Exercise-1 Basic SQL Statements In this exercise, students will be able to do the following: Understanding the capabilities of Select statements Execute a basic select statement Capabilities of SELECT Statement: Select, Project, Join Basic SELECT statement: Eg: Select * { [DISTINCT] column Expression [alias] } From table; Select * from employees; Select employee_name, employee_id from employees; Using Arithmetic Expressions Eg: + Add - Subtract * Multiply / Division Select last_name, salary, salary+1000 from employees; Defining null value: A null is a value that is unavailable, unassigned, unknown or inapplicable Coloumn Alias: Renames a column heading Immediately follows the column name Can also use as keyword between column name and alias name Requires double quotation marks if alias contains space

Concatenation Operator: Concatenates columns or character strings to other columns Represented by two vertical bars Elimination of duplicate rows: Eg: Eliminate duplicate values by using the distinct keyword in the select clause Select distinct department_id from employees; Displaying table structure: Desc tablename;

In this exercise, students will be able to do the following: Limit the rows retrieved by the query Sort the rows retrieved by the query Limit the rows using WHERE Clause: Eg: Exercise-2 Restricting and Sorting Data Select * { [DISTINCT] column Expression [alias] } From table [WHERE Condition(s)]; Select employee_name, employee_id, department_id from employees wheredepartment_id=90; Comparison conditions: Eg: = Equal to > Greater than >= Greater than or Equal to < Less than <= Less than or Equal to <> Not equal to Select last_name, salary from employees Where salary>5000;

Other comparison conditions: Between.and. IN(set) Like IS Null Between two values inclusive match any of a list of values match a character pattern Is a null value Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns TRUE if the following condition is FALSE

Exercise-3 Single Row Functions In this exercise, students will be able to do the following: Describe various types of functions available in SQL Use character, number and date functions in select statement Single Row Functions: They accept one or more arguments and return one value for each row returned by the query Character Functions: Accept character input and can return both character and number functions. Number Functions:

Date Functions: General Functions: list. These functions work with any data types and pertain to the use of null values in the expression

Exercise-4 Displaying data from multiple tables In this exercise, students will be able to do the following: Write select statements to access data from multiple tables using equality and non equality joins View data that generally does not meet a join condition by using outer joins Join a table to itself by using a self join Equijoin: Equijoins are also called as inner joins or simple joins Non-Equijoin: It is a join condition containing something other than an equality operator

Outer Join: Full outer join Left outer join Right outer join Left outer join: Right outer join: Full outer join:

Self Join:

Exercise-5 Creating and Managing Tables In this exercise, students will be able to do the following: Describe the main database objects Create tables Describe the data types that can be used when specifying column definition Alter table definitions Drop the tables Database Objects: Table, View, Sequence, Index, Synonym DDL Commands : CREATE, ALTER, DROP Create Table: Eg. CREATE TABLE emp( empid number(5), ename varchar(30), salary number(8,2), doj date)); Data Types Varchar, char, number(p,s), date, long, clob, date Alter Table Use the ALTER TABLE statement to Add a new column Modify an existing column Define a default value for the new column Drop a column

Eg. ALTER TABLE emp ADD(mail_id varchar(30)); ALTER TABLE emp modify (mail_id varchar(40)); ALTER TABLE emp DROP COLUMN mail_id; Dropping a Table All data and structure in the table is deleted Any pending transactions are committed All indexes are dropped You cannot roll back the DROP TABLE statement. Eg. DROP TABLE emp;

Exercise-6 Including Constraints In this exercise, students will be able to do the following: Describe constraints Create and maintain constraints Constraints Constraints enforce rules at the table level Constraints prevent the deletion of a table if there are dependencies Types - NOT NULL - UNIQUE - PRIMARY KEY - FOREIGN KEY - CHECK Eg. CREATE TABLE emp ( empid NUMBER(5) PRIMARY KEY, ename VARCHAR(30) NOT NULL, salary NUMBER(8,2) CHECK salary>0, deptid NUMBER(2) REFERENCES dept(dept_no));

Exercise-7 Manipulating Data In this exercise, students will be able to do the following: Describe each DML statement Insert rows into a table Update rows in a table Delete rows from a table Merge rows in a table DML statements INSERT, UPDATE, DELETE, MERGE Adding new row into a table INSERT INTO emp VALUES(101, vadivu,33000, Programmer, 01-jan-98 ); Modifying the existing data UPDATE emp SET salary = 10000 WHERE id = 101; Deleting rows DELETE FROM emp where id = 101; Merge Provides the ability to conditionally update or insert data into a database table. Performs an UPDATE if the row exists, and an INSERT if it is a new row. Eg. MERGE INTO copy_emp c USING employees e ON (c.empid = e.empid) WHEN MATCHED THEN UPDATE SET c.ename = e.ename, c.salary = e.salary WHEN NOT MATCHED THEN INSERT VALUES(e.empid, e.ename, e.salary);

Exercise-8 Aggregating Data Using Group Functions In this exercise, students will be able to do the following: Identify the available group functions Describe the use of group functions Group data using the GROUP BY clause Include or Exclude grouped rows by using the HAVING clause Group Functions: operates on sets of rows to give one result per group. Types of Group Functions: AVG COUNT MAX MIN SUM Eg. SELECT SUM(salary) FROM employees; GROUP BY clause Used to create groups of data. Eg. SELECT department_id, AVG(salary) FROM employees GROUP BY department_id;

GROUP BY HAVING clause Use the HAVING clause to restrict groups. Eg. SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING SUM(SALARY)>20000;

Exercise-9 Subqueries In this exercise, students will be able to do the following: Describe the types of problem that subqueries can solve List the types of subqueries Write single row and Multiple row subqueries Subquery Syntax: SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM table); The subquery executes before the main query. The result of the subquery is used by the main query. Guidelines for using Subqueries Enclose subqueries in parantheses Place subqueries on the right side of the comparison condition Types of Subqueries 1. Single-row subquery: queries that return only one row from the inner SELECT statement. 2. Multiple-row subquery: Queries that return more than one row from the inner SELECT statement. Multiple-row comparison operators: IN, ANY, ALL