Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

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

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

Oracle Database SQL Basics

Intermediate SQL: Aggregated Data, Joins and Set Operators

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

KORA. RDBMS Concepts II

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

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

Retrieving Data from Multiple Tables

Join, Sub queries and set operators

Restricting and Sorting Data. Copyright 2004, 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

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

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

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

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

CGS 3066: Spring 2017 SQL Reference

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

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

Querying Data with Transact SQL

Database Programming with SQL

DUE: 9. Create a query that will return the average order total for all Global Fast Foods orders from January 1, 2002, to December 21, 2002.

Oracle Database 11g: SQL and PL/SQL Fundamentals

Full file at

Database Management Systems,

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

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

Database Programming with SQL

ÇALIŞMA TEST SORULARI

Introduction to Oracle9i: SQL

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

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

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

SQL Interview Questions

Jarek Szlichta

An Introduction to Structured Query Language

An Introduction to Structured Query Language

An Introduction to Structured Query Language

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Oracle SQL & PL SQL Course

An Introduction to Structured Query Language

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

An Introduction to Structured Query Language

5. Single-row function

Oracle Syllabus Course code-r10605 SQL

Oracle Database: SQL and PL/SQL Fundamentals

CSC Web Programming. Introduction to SQL

Implementing Table Operations Using Structured Query Language (SQL) Using Multiple Operations. SQL: Structured Query Language

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

Data Infrastructure IRAP Training 6/27/2016

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

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

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Oracle Database 10g: SQL Fundamentals I

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

Sun Certified MySQL Associate

MTA Database Administrator Fundamentals Course

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

Oracle 1Z Oracle Database 11g SQL Fundamentals I. Download Full Version :

Fundamentals of Information Systems, Seventh Edition

Advanced SQL Tribal Data Workshop Joe Nowinski

Lab # 6. Data Manipulation Language (DML)

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

RDBMS. SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in a relational database.

Querying Data with Transact-SQL

Chapter. Relational Database Concepts COPYRIGHTED MATERIAL

Sql Server Syllabus. Overview

DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR

Course Outline. MySQL Database Administration & Design. Course Description: Pre-requisites: Course Content:

COMP 244 DATABASE CONCEPTS & APPLICATIONS

CS2 Current Technologies Lecture 2: SQL Programming Basics

Querying Data with Transact-SQL

EXISTS NOT EXISTS WITH

ORACLE CERTIFIED ASSOCIATE ORACLE DATABASE 11g ADMINISTRATOR

Oracle Database 10g: Introduction to SQL

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer,

A Unit of SequelGate Innovative Technologies Pvt. Ltd. All Training Sessions are Completely Practical & Real-time

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

Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)

Chapter-14 SQL COMMANDS

Data Manipulation Language

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:

RMOUG Training Days 2018

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data.

Relational Database Management Systems for Epidemiologists: SQL Part II

Unit Assessment Guide

tablename ORDER BY column ASC tablename ORDER BY column DESC sortingorder, } The WHERE and ORDER BY clauses can be combined in one

CISC 3140 (CIS 20.2) Design & Implementation of Software Application II

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

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

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL

Creating Other Schema Objects

SQL Commands & Mongo DB New Syllabus

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

Transcription:

2017 Institute of Aga Network Database LECTURER NIYAZ M. SALIH

Database: A Database is a collection of related data organized in a way that data can be easily accessed, managed and updated. Any piece of information can be a data, for example name of your school. Database is actually a place where related piece of information is stored and various operations can be performed on it. Database Management System (DBMS): A DBMS is software that allows creation, definition and manipulation of database. DBMS is actually a tool used to perform any kind of operation on data in database. DBMS also provides protection and security to database. It maintains data consistency in case of multiple users. Here are some examples of popular DBMS, MySQL, Oracle, Sybase, Microsoft Access and IBM DB2 etc. Components of Database System: The database system can be divided into four components.

Users: Users may be of various types such as DB administrator, System developer and End users. Database application: Database application may be Personal, Departmental, Enterprise and Internal. DBMS: Software that allow users to define, create and manages database access, Ex: MySQL, Oracle etc. Database: Collection of logical data. Functions of DBMS: Provides data Independence Concurrency Control Provides Recovery services Provides Utility services Provides a clear and logical view of the process that manipulates data. Advantages of DBMS: Segregation of application program. Minimal data duplicity. Easy retrieval of data. Reduced development time and maintenance need.

Data Abstraction: Database systems are made-up of complex data structures. To ease the user interaction with database, the developers hide internal irrelevant details from users. This process of hiding irrelevant details from user is called data abstraction. Levels of abstraction: We have three levels of abstraction: Physical level: This is the lowest level of data abstraction. It describes how data is actually stored in database. You can get the complex data structure details at this level. Logical level: This is the middle level of 3-level data abstraction architecture. It describes what data is stored in database. View level: Highest level of data abstraction. This level describes the user interaction with database system.

Database model: A database model is a type of data model that determines the logical structure of a database and fundamentally determines in which manner data can be stored, organized and manipulated. The most popular example of a database model is the relational model, which uses a table-based format. Types of database models: There are many kinds of data models. Some of the most common ones include: Relational model Hierarchical database model Network model Object-oriented database model Entity-relationship model Relational model: A relational database (RDB) is a collective set of multiple data sets organized by tables, records and columns. RDBs establish a well-defined relationship between database tables. Tables communicate and share information, which facilitates data search ability, organization and reporting.

Hierarchical model: A hierarchical database model is a data model in which the data is organized into a tree-like structure. The data is stored as records which are connected to one another through links. A record is a collection of fields, with each field containing only one value. The entity type of a record defines which fields the record contains. Network model: The network model builds on the hierarchical model by allowing many-to-many relationships between linked records, this model allows each child to have multiple parents.

Object-oriented database model: This model defines a database as a collection of objects, or reusable software elements, with associated features and methods. Entity Relationship model(er): An entity relationship model, also called an entity-relationship (ER) diagram is a way of graphically representing the logical relationships of entities (or objects) in order to create a database.

Entity: An entity in an ER Model is a real-world entity having properties called attributes. Every attribute is defined by its set of values called domain. For example, in a school database, a student is considered as an entity. Student has various attributes like name, age, class, etc. Relationship: The logical association among entities is called relationship. Relationships are mapped with entities in various ways. Mapping cardinalities define the number of association between two entities. Mapping cardinalities one to one one to many many to one many to many

Database Administrator: A Database Administrator is a person or a group of person who are responsible for managing all the activities related to database system. This job requires a high level of expertise by a person or group of person. There are very rare chances that only a single person can manage all the database system activities so companies always have a group of people who take care of database system. Role and duties of Database Administrator: Installing and Configuration of database: DBA is responsible for installing the database software. He configures the software of database and then upgrades it if needed. There are many databases software like oracle, Microsoft SQL and MySQL in the industry so DBA decides how the installing and configuring of these database software will take place. Deciding the hardware device Depending upon the cost, performance and efficiency of the hardware, it is DBA who have the duty of deciding which hardware devise will suit the company requirement. It is hardware that is an interface between end users and database so it needed to be of best quality. Managing Data Integrity Data integrity should be managed accurately because it protects the data from unauthorized use. DBA manages relationship between the data to maintain data consistency. Database design The logical design of the database is designed by the DBA. Also a DBA is responsible for physical design, external model design, and integrity control.

Decides Data Recovery and Back up method If any company is having a big database, then it is likely to happen that database may fail at any instance. It is require that a DBA takes backups of entire database in regular time span. DBA has to decide that how much data should be backed up and how frequently the back should be taken. Also the recovery of data base is done by DBA if they have lost the database. Tuning Database Performance Database performance plays an important role for any business. If user is not able to fetch data speedily then it may loss company business. So by tuning a modifying SQL commands a DBA can improves the performance of database. Capacity Issues All the databases have their limits of storing data in it and the physical memory also has some limitations. DBA has to decide the limit and capacity of database and all the issues related to it. Database accessibility DBA writes subschema to decide the accessibility of database. He decides the users of the database and also which data is to be used by which user. No user has to power to access the entire database without the permission of DBA. Improve query processing performance Queries made by the users should be performed speedily. As we have discussed those users need fast retrieval of answers so DBA improves query processing by improving their performance.

Decides validation checks on data DBA has to decide which data should be used and what kind of data is accurate for the company. So he always puts validation checks on data to make it more accurate and consistence. Monitoring performance If database is working properly then it doesn t mean that there is no task for the DBA. Yes of course, he has to monitor the performance of the database. A DBA monitors the CPU and memory usage. Decides content of the database A database system has many kind of content information in it. DBA decides fields, types of fields, and range of values of the content in the database system. One can say that DBA decides the structure of database files. Database implementation Database has to be implemented before anyone can start using it. So DBA implements the database system. DBA has to supervise the database loading at the time of its implementation.

Structured Query Language (SQL): What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in a relational database. SQL is the standard language for Relational Database System. All the Relational Database Management Systems (RDBMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their standard database language. Why SQL? SQL is widely popular because it offers the following advantages: Allows users to access data in the relational database management systems. Allows users to describe the data. Allows users to define the data in a database and manipulate that data. Allows to embed within other languages using SQL modules, libraries & precompilers. Allows users to create and drop databases and tables. Allows users to create view, stored procedure, functions in a database. Allows users to set permissions on tables, procedures and views. SQL Commands: The standard SQL commands to interact with relational databases are CREATE, SELECT, INSERT, UPDATE, DELETE and DROP. These commands can be classified into the following groups based on their nature

DDL - Data Definition Language: Data Definition Language (DDL) is a standard for commands that define the different structures in a database. DDL statements create, modify, and remove database objects such as tables, indexes, and users. DML - Data Manipulation Language: A data manipulation language (DML) is a family of syntax elements similar to a computer programming language used for selecting, inserting, deleting and updating data in a database.

DCL - Data Control Language: Data control language is a syntax similar to a computer programming language used to control access to data stored in a database (Authorization). Table: The data in an RDBMS is stored in database objects which are called as tables. This table is basically a collection of related data entries and it consists of numerous columns and rows.

Field: Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS table consist of ID, NAME, AGE, ADDRESS and SALARY. A field is a column in a table that is designed to maintain specific information about every record in the table. Record: A record is also called as a row of data is each individual entry that exists in a table. For example, there are 7 records in the above CUSTOMERS table. Following is a single row of data or record in the CUSTOMERS table: Column: A column is a vertical entity in a table that contains all information associated with a specific field in a table. For example, a column in the CUSTOMERS table is ADDRESS, which represents location description and would be as shown in the CUSTOMERS table.

Oracle SQL Commands: SELECT statement The SELECT statement is used to select data from a database. SELECT Syntax SELECT department_id,department_name,manager_id,location_id FROM hr.departments SELECT * FROM hr.departments; DISTINCT The SELECT DISTINCT statement is used to return only distinct (different) values. Syntax SELECT DISTINCT department_id From hr.employees

Arithmetic Expression: SELECT last_name,salary,salary+300 From hr.employees SELECT last_name,salary,12*salary+100 From hr.employees SELECT last_name,salary,12*(salary+100) From hr.employees NULL Value: 0 (zero) means value. Space means character. Null means unknown value or missing value. Some fields may contains NULL value when there is no UNNULL constraint on it. SELECT last_name,job_id,salary,commission_pct From hr.employees SELECTlast_name,job_id,salary,12*salary*commission_pct From hr.employees ALIASES: Aliases are often used to make column names more readable. Syntax SELECT last_name as name,commission_pct comm From hr.employees SELECT last_name "Name",salary * 12 "Annual Salary From hr.employees

Concatenation Operator( ): SELECT last_name job_id as "Employees From employees SELECT last_name ' is a ' job_id as "Employees From employees SELECT last_name ': 1 Month Salary=' salary monthly From employees DESCRIBE: DESC employees SELECT * FROM tab WHERE clause: The WHERE clause is used to filter records. The WHERE clause is used to extract only those records that fulfill a specified condition. SELECT employee_id,last_name,job_id,department_id from employees WHERE department_id=90 SELECT last_name,job_id,department_id from employees WHERE job_id='sa_rep SELECT last_name,job_id,department_id from employees WHERE last_name='whalen SELECT employee_id,last_name,salary,manager_id FROM employees WHERE manager_id IN (100,101,102)

SELECT employee_id,last_name,salary,manager_id FROM employees WHERE manager_id =101 or manager_id =102 or manager_id =103 SELECT employee_id,last_name,salary,manager_id FROM employees WHERE last_name IN ('Hartstein','Vargas') SELECT first_name FROM employees WHERE first_name like 'S% SELECT last_name,hire_date FROM employees WHERE hire_date like '95% SELECT last_name FROM employees WHERE last_name like '_o%' LOGICAL PARAMETERS: AND Syntax SELECT employee_id,last_name,job_id,salary FROM employees WHERE salary>=10000 AND job_id like '%MAN%' OR Syntax SELECT employee_id,last_name,job_id,salary FROM employees WHERE salary>=10000 OR job_id like '%MAN%'

NOT Syntax SELECT last_name,job_id FROM employees where job_id NOT IN ('IT_PROG ) ORDER BY: The ORDER BY keyword is used to sort the result-set in ascending or descending order. Syntax SELECT last_name,job_id,department_id,hire_date FROM employees ORDER BY hire_date SELECT last_name,job_id,department_id,hire_date FROM employees ORDER BY hire_date DESC SELECT last_name,salary FROM employees ORDER BY 2 DESC SELECT last_name,department_id,salary FROM employees ORDER BY department_id,salary

CASE function The CASE function lets you evaluate conditions and return a value when the first condition is met (like an IF-THEN-ELSE statement). Syntax SELECT last_name,salary,job_id, CASE job_id WHEN 'IT_PROG' THEN 1.10*salary WHEN 'AD_VP' THEN 1.15*salary WHEN 'AD_PRES' THEN 1.20*salary ELSE salary END "Revised salary" FROM employees DECODE function The DECODE function has the functionality of an IF-THEN-ELSE statement. Syntax

SELECT last_name,salary,job_id, DECODE (job_id,'it_prog',1.10*salary, 'AD_VP',1.15*salary, 'AD_PRES',1.20*salary,salary) FROM employees Aggregation The following are the most commonly used SQL aggregate functions: AVG calculates the average of a set of values. COUNT counts rows in a specified table or view. MIN gets the minimum value in a set of values. MAX gets the maximum value in a set of values. SUM calculates the sum of values. SELECT AVG(salary),MAX(salary),MIN(salary),SUM(salary) FROM employees WHERE job_id LIKE '%REP%' SELECT MIN(hire_date),MAX(hire_date) FROM employees SELECT MIN(last_name),MAX(last_name) FROM employees SELECT COUNT(*) FROM employees WHERE department_id=50 SELECT COUNT(commission_pct) FROM employees WHERE department_id=80 SELECT COUNT(department_id) FROM employees SELECT COUNT(DISTINCT department_id) FROM employees SELECT AVG(commission_pct) FROM employees

SELECT department_id,avg(salary) FROM employees WHERE AVG(salary)>8000 GROUP BY department_id (Error) SELECT department_id,avg(salary) FROM employees HAVING AVG(salary)>8000 GROUP BY department_id SELECT department_id,max(salary) FROM employees GROUP BY department_id HAVING MAX(salary)>10000 SELECT MAX(AVG(salary)) FROM employees GROUP BY department_id

SQL Joins A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Self-JOIN is a regular join, but the table is joined with itself. SELECT worker.last_name ' works for ' manager.last_name FROM employees worker, employees manager WHERE worker.manager_id= manager.employee_id Cross join: The SQL CROSS JOIN produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table SELECT last_name,department_name FROM employees CROSS JOIN departments

(INNER) JOIN: Returns records that have matching values in both tables SELECT e.last_name, e.department_id,d.department_name FROM employees e INNER JOIN departments d ON (e.department_id=d.department_id) LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the right table SELECT e.last_name, e.department_id,d.department_name FROM employees e LEFT OUTER JOIN departments d ON (e.department_id=d.department_id) RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from the left table SELECT e.last_name, e.department_id,d.department_name FROM employees e RIGHT OUTER JOIN departments d ON (e.department_id=d.department_id)

FULL (OUTER) JOIN: Return all records when there is a match in either left or right table SELECT e.last_name, e.department_id,d.department_name FROM employees e FULL OUTER JOIN departments d ON (e.department_id=d.department_id)