Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Cursor-style processing involves retrieving data from the cursor, one row at a time.

18/12/2020 Client: saad24vbs Deadline: 14 Days

SQL and Oracle SQL (Week - 6,7,8 & 9)



Avimanyou Vatsa, Ph.D.

Department of Computer Science Fairleigh Dickinson University


Slides are adapted and modified from c© Carlos Coronel, Steven Morris, Silberschatz, Korth, and Sudarshan. All rights reserved.


September 23, 2020


Last Week, Quick Review

CLO – ER Diagram (individual) Extended Entity Relationship (EER) Model Specialization & Generalization (Inheritance) Time Variant Data ERD with FAN Trap Redundant Relationship Quiz – EERD


This Week, Learning Objectives

The basic commands and functions of SQL How to use SQL for data administration (to create tables and indexes)


How to use SQL for data manipulation (to add, modify, delete, and retrieve data)


How to use SQL to query a database for useful information How to use the advanced SQL JOIN operator syntax About the different types of subqueries and correlated queries How to use SQL functions to manipulate dates, strings, and other data


About the relational set operators UNION, UNION ALL, INTERSECT, and MINUS


How to create and use views and updatable views How to create and use triggers and stored procedures How to create embedded SQL


Structured Query Language (SQL)


Categories of SQL functions:


Data definition language (DDL) Data manipulation language (DML)


Nonprocedural language with basic command vocabulary set of less than 100 words


Differences in SQL dialects are minor


Command or Option Description

CREATE SCHEMA Authorization Create a database schema

CREATE TA- BLE Create new table in the user’s database schema

NOT NULL Ensure that a column will not have NULL values

UNIQUE Ensure that a column will not have duplicate values

PRIMARY KEY Define a primary key for a table

FOREIGN KEY Define a foreign key for a table

DEFAULT Define a default value for a column (when no value is given)

CHECK Validate data in an attribute

Command or Option Description

CREATE INDEX Create an index for a table

CREATE VIEW Create a dynamic subset of rows and columns from one or more tables

ALTER TABLE Modifies a table’s defination (adds, modifies, or deletes attributes or constraints)

CREATE TA- BLE AS create a new table based on a query in the user’s database schema

DROP TABLE Permanently deletes a table (and its data)

DROP INDEX Permanently deletes an index

DROP VIEW Permanently deletes a view

Command or Option Description

INSERT Insert row(s) into a table

SELECT Selects attributes from rows in one or more ta- bles or views

WHERE Restricts the selection of rows based on a con- ditional expression

GROUP BY Groups the selected rows based on one or more attributes

HAVING Restricts the selection of grouped rows based on a condition

ORDER BY Orders the selected rows based on one or more attributes

UPDATE Modifies an attribute’s values in one or more table’s rows

DELETE

COMMIT

ROLLBACK

=, <,>,≤,≥ , <>, ! =


AND, OR, NOT

BETWEEN

IS NULL


Description

Deletes one or more rows from a table


Permanently saves data changes


Restores data to its original values


Comparision Operators

Used in conditional expressions


Logical Operators

Used in conditional expressions


Special Operators

Checks whether an attribute value is within a range


Checks whether an attribute value is null


Command or Option Description

LIKE Checks whether an attribute value matches a given string pattern

IN Checks whether an attribute value matches any value within a value list

EXISTS Checks whether a subquery returns any row

DISTINCT Limits values to unique values

Aggregate Functions Used with SELECT to return mathematical summaries on columns

COUNT Returns the number of rows with non-null values for a given columns

MIN Returns the minimum attribute value found in a given column

Command or Option Description

MAX Returns the maximum attribute value found in a given column

SUM Returns the sum of all values for a given column

AVG Returns the average of all values for a given column

Oracle & Front-End Resources

1 Reference manual: https://docs.oracle.com/en/


database/oracle/oracle-database/19/index.html

2 Web technology tools: https://www.w3schools.com/ 3 Programming Courses: CSCI 6810/4380(Java) or CSCI


3444/6844/Info 4844 - Programming for Internet, C, C++, C#, Python.


Oracle SQL

Open Oracle code file (*.sql) and execute on sqlplus command prompt.


Install ATOM (texteditor) on your machine

1 Go to: https://github.com/atom/atom


2 Go to releases >> Latest release instead of Beta version >>


atom-mac.zip


3 Download and open it and drag and drop in applications. 4 Open Atom >> Go to “ATOM” menu and open “Install Shell


Command”.


Download and execute “musicForeignKey-Oracle.sql” code on SQL terminal.


Download “createStudent.sql” & “sql book add tables.sql” & “AppendixD.pdf” from blackboard and open *.sql code in any text editor (Atom, textEdit, notepad ++, vi, emacs, etc).


Optional: Copy these *.sql files on opus server using following command at terminal or Power Shell:


scp -r Source address of file Destination address of file


Common SQL Data Types

Creating Table Structures

Use one line per column (attribute) definition Use spaces to line up attribute characteristics and constraints Table and attribute names are fully capitalized


Features of table creating command sequence:


NOT NULL specification ensures data entry UNIQUE specification avoids duplicated values


Table d


SQL Constraints


SQL Indexes

When primary key is declared, DBMS automatically creates unique index


The CREATE INDEX command can be used to create indexes on the basis of any selected attribute UNIQUE qualifier prevents a value that has been used before Composite indexes prevent data duplication


To delete an index use the DROP INDEX command


NOTE: SQL names are case insensitive (i. e. you may use upper or lower-case letters.)


User–Defined Types & Domains

create type construct in SQL creates user–defined type:


create type Dollars as numeric (12,2) final


Example: create table department(dept name varchar (20), building varchar (15), budget Dollars);


Creates user-defined domain types


create domain person name char(20) not null

Example: create domain degree level varchar(10) constraint degree level test


check (value in (’Bachelors’, ’Masters’, ’Doctorate’));


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 (whose interpretation is left to an application outside of the database system)


clob: character large object


Object is a large collection of character data


Note: When a query returns a large object, a pointer is returned rather than the large object itself.


Advanced SQL

SQL Join Expression Styles

Subqueries & Correlated Queries

Subquery is a query inside another query Subquery can return:


One single value - One column and one row A list of values - One column and multiple rows A virtual table - Multicolumn, multirow set of values No value - Output of the outer query might result in an error or a null empty set


Inline subquery: Subquery expression included in the attribute list that must return one value


Correlated Subqueries

Executes once for each row in the outer query Inner query references a column of the outer subquery Can be used with the EXISTS special operator


SQL Functions

Functions always use a numerical, date, or string value Value may be part of a command or may be an attribute located in a table


Function may appear anywhere in an SQL statement where a value or an attribute can be used


SQL Functions:


Virtual Tables: Creating a View

View: Virtual table based on a SELECT query Base tables: Tables on which the view is based CREATE VIEW statement: Data definition command that stores the subquery specification in the data dictionary


CREATE VIEW command: CREATE VIEW viewname AS SELECT query


Updatable Views

Used to update attributes in any base tables used in the view Batch update routine: Pools multiple transactions into a single batch to update a master table field in a single operation


Updatable view restrictions


GROUP BY expressions or aggregate functions cannot be used Set operators cannot be used JOINs or group operators cannot be used


Authorization Specification in SQL

grant statement is used to confer authorization


grant < privilege list > on < relation name or view name > to < user list > < user list > is:


a user-id

public, which allows all valid users the privilege granted

A user role

Granting a privilege on a view does not imply granting any privileges on the underlying relations.


The grantor of the privilege must already hold the privilege on the specified item (or be the database administrator). Privileges in SQL: Select, Insert, Update, Delete, All Privilleges.


Revoke

revoke statement is used to revoke authorization.


Revoking Authorization in SQL

revoke < privilege list > on < relation name or view name > from < user list >


Example:


revoke select on branch from U1,U2,U3

Examples

Conditional Updates

update instructor set salary = case when salary = 100000 then salary ∗ 1.05 else salary ∗ 1.03 end


Recompute and update tot creds value for all students update student S


set tot cred = (select sum(credits) from takes, course where takes.course id = course.course id and S.ID= takes.ID. and takes.grade <> ’F’ and takes.grade is not null)


PL/SQL

Procedural SQL

Performs a conditional or looping operation by isolating critical code and making all application programs call the shared code:


Yields better maintenance and logic control


Persistent stored module (PSM): Block of code containing:


Standard SQL statements Procedural extensions that is stored and executed at the DBMS server


Procedural Language SQL (PL/SQL)


Use and storage of procedural code and SQL statements within the database Merging of SQL and traditional programming constructs


Procedural code is executed as a unit by DBMS when invoked by end user


End users can use PL/SQL to create:


Anonymous PL/SQL blocks and triggers Stored procedures and PL/SQL functions


PL/SQL Basic Data Types

Triggers

Procedural SQL code automatically invoked by RDBMS when given data manipulation event occurs


Parts of a trigger definition


Triggering timing – Indicates when triggers PL/SQL code executes Triggering event – Statement that causes the trigger to execute Triggering level – Statement- and row-level Triggering action – PL/SQL code enclosed between the BEGIN and END keywords


DROP TRIGGER trigger name command: Deletes a trigger without deleting the table Trigger action based on DML predicates: Actions depend on the type of DML statement that fires the trigger


PL/SQL Processing with Cursors

Cursor: Special construct used to hold data rows returned by a SQL query


Implicit cursor: Automatically created when SQL statement returns only one value


Explicit cursor: Holds the output of a SQL statement that may return two or more rows


Cursor–style processing involves retrieving data from the cursor one row at a time:

Current row is copied to PL/SQL variables Cursor Attributes:


Cursor Processing Commands

Stored Procedures

Named collection of procedural and SQL statements Advantages


Reduce network traffic and increase performance Reduce code duplication by means of code isolation and code sharing


PL/SQL Stored Functions

Stored function: Named group of procedural and SQL statements that returns a value:


As indicated by a RETURN statement in its program code


Can be invoked only from within stored procedures or triggers


SQL statements contained within an application programming language


Host language: Any language that contains embedded SQL statements


Differences between SQL and procedural languages: Run-time mismatch


SQL is executed one instruction at a time Host language runs at client side in its own memory space


Processing mismatch

Conventional programming languages process one data element at a time


Newer programming environments manipulate data sets in a cohesive manner


Embedded SQL

Data type mismatch


Data types provided by SQL might not match data types used in different host languages


Embedded SQL framework defines

Standard syntax to identify embedded SQL code within the host language


Standard syntax to identify host variables Communication area used to exchange status and error information between SQL and host language


Static SQL: Programmer uses predefined SQL statements and parameters


SQL statements will not change while application is running


Dynamic SQL: SQL statement is generated at run time


Attribute list and condition are not known until end user specifies them Slower than static SQL Requires more computer resources


SQL Status and Error Reporting Variables

Thanks!


Thank You! Questions?


Applied Sciences

Architecture and Design

Biology

Business & Finance

Chemistry

Computer Science

Geography

Geology

Education

Engineering

English

Environmental science

Spanish

Government

History

Human Resource Management

Information Systems

Law

Literature

Mathematics

Nursing

Physics

Political Science

Psychology

Reading

Science

Social Science

Home

Blog

Archive

Contact

google+twitterfacebook

Copyright © 2019 HomeworkMarket.com

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

University Coursework Help
Top Essay Tutor
Helping Hand
Homework Guru
Writer Writer Name Offer Chat
University Coursework Help

ONLINE

University Coursework Help

Hi dear, I am ready to do your homework in a reasonable price.

$37 Chat With Writer
Top Essay Tutor

ONLINE

Top Essay Tutor

I have more than 12 years of experience in managing online classes, exams, and quizzes on different websites like; Connect, McGraw-Hill, and Blackboard. I always provide a guarantee to my clients for their grades.

$40 Chat With Writer
Helping Hand

ONLINE

Helping Hand

Hello, I an ranked top 10 freelancers in academic and contents writing. I can write and updated your personal statement with great quality and free of plagiarism as I am a master writer with 5 years experience in similar ps and research writing projects. Kindly send me more information about your project. You can award me any time as I am ready to start your project curiously. Waiting for your positive response. Thank you!

$30 Chat With Writer
Homework Guru

ONLINE

Homework Guru

Hi dear, I am ready to do your homework in a reasonable price and in a timely manner.

$37 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Experiment 5 the importance of cell cycle control - We shall fight on the beaches techniques - Urgent 1 - Bishop stopford school enfield staff list - Canton and hall daytripper watch review - Discussion - Bbb vvv gg mahal - Where i m calling from summary - Gopro case study marketing - Design and analysis of experiments solutions - IP 5 - Literal meaning of the poem the road not taken - Political cartoon dred scott decision - Descriptive statistics and data visualization - All summer in day - Should the pledge of allegiance have under god - The austrian oak strongman - 12 on center framing - Variables Into Knowledge - Motivation - Eleco ltd slot machine manual - Investigating the effect of acid rain on seed germination - X 2 22x complete the square - Urgant - The tempest quotes prospero revenge - 124b victoria road northcote - Statistics quizzes - Baking soda and vinegar limiting reactant lab - Health care system in usa ppt - Which ethical system embraces human's inclination for self preservation - A social change model of leadership development guidebook - Powershell web access gateway allows _______ - Chemical spill procedures template - Lab Report #11 - What are concrete nouns - Personal and professional development in nursing - Hacking into harvard case 2.1 - Mkt630 DQ3 - La fitness swot analysis - What is orchestration in biztalk - Modulus 11 check digit - Today learning exp 105 - Kumar abbas and fausto 2015 - Www sbha org uk - Parallel circuit with two batteries - Siberian husky welfare association - Descriptive paragraph about food - Module 01 Project - Financial Statements - Statistics course weekly lab - Paper - Ian wallace psychologist forestway - Devilbiss fluid tip chart - What are the characteristics of chemical equilibrium - Burglar alarm keypad 9800 - Practice note sc cl 3 - Greenough hamlet cafe menu - Which of the following statements is always true concerning the reporting of debt service funds? - Correctional processes - Www udel edu biology ketcham microscope scope html - Diabetes and homeostasis worksheet - Week 4 Assignment: Journal - Brisbane council interactive mapping - Fat city special education video - How to cut glass tube - Should vaccines be required essay - Essay - Briefly explain the basic characteristics of ordinary life policies - Symbolism in the second coming by william butler yeats - Education as a social institution essay - Capstone make up work 1 - Make a tree diagram in word - Amortisseur winding in synchronous motor - Draw six isomeric cyclopentanes of molecular formula - Lightning panel board symbol - Freezing temperature of corn syrup - Hodson phonological processes chart - Describe the role of three external services during an emergency - La mancha neath christmas menu - What project management software did arnold palmer utilize? - The new colossus paraphrase - Bach trumpet serial numbers - Ladybug killer the shack - Nestle ice cream in cuba case study - Herqa accreditation checklist pdf - Cerec training level 1 - Dorian majied - Idea 10 audit software free download - E waste solutions pptiso 16812 vs api 660 - Does domino's deliver heart shaped pizzas - Current event - NURS-6050N-66/NURS-6050C-66-Policy & Advocacy - Cms 1500 mcgraw hill - Earthquake and seismic waves worksheet answers - Affidavit evidence in chief - Canare f10 rca plug - PowerPoint (12–15-slide PowerPoint presentation) - Cultural Diversity - Help 2 - Mcconnell brue flynn economics 21th edition pdf - Electron configuration for diatomic molecules