Centralized

Embed Size (px)

Citation preview

  • 8/11/2019 Centralized

    1/14

    Centralized Vs DistributedCentralized Systems:A modern, general-purpose computer system consists of one to a few

    CPUs & a number of device controllers that are connected through a common bus that

    provides access to shared memory. The CPUs have local cache memories that store local

    copies of parts of the memory, to speed up access to data. Each device controller is in charge

    of a specific type of device (for example, a disk drive, an audio device, or a video display). The

    CPUs & the device controllers can execute concurrently, competing for memory access. Cache

    memory reduces the contention for memory access, since it reduces the number of times

    that the CPU needs to access shared memory.In a distributed database system, the database is stored on several computers. The

    computers in a distributed system communicate with one another through various

    communication media, such as high-speed networks or telephone lines. They do not share

    main memory or disks. The computers in a distributed system may vary in size & function,

    ranging from workstations up to mainframe systems.

    The main difference between centralized & distributed databases is that the distributed

    databases are typically geographically separated, are separately administered, & have slower

    interconnection. Also in distributed databases we differentiate

    between local& globaltransactions. A local transactionis one that accesses data only from

    sites where the transaction originated. A global transaction, on the other hand, is one that

    either accesses data in a site different from the one at which the transaction was initiated, or

    accessed data in several different sites.

  • 8/11/2019 Centralized

    2/14

    E R Diagram

    Advantages

    Conceptual simplicity

    Visual representation

    Effective communication

    Integration with the relational database model

    Disadvantages

    Limited constraint representation

    Limited relationship representation No representation of data manipulation

    Loss of information

  • 8/11/2019 Centralized

    3/14

    Using a Subquery

    to Solve a Problem

    Who has a salary greater than Abels?

    Which employees have salaries greater

    than Abels salary?

    Main query:

    What is Abels salary?

    Subquery:

  • 8/11/2019 Centralized

    4/14

    The subquery (inner query) executes once beforethe main query (outer query).

    The result of the subquery is used by the mainquery.

    SELECT select_list

    FROM table

    WHERE expr operator

    (SELECT select_list

    FROM table);

    Subquery Syntax

  • 8/11/2019 Centralized

    5/14

    SELECT last_name, salary

    FROM employees

    WHERE salary >

    (SELECT salary

    FROM employeesWHERE last_name = 'Abel');

    Using a Subquery

    11000

  • 8/11/2019 Centralized

    6/14

    Guidelines for Using Subqueries

    Enclose subqueries in parentheses.

    Place subqueries on the right side of the

    comparison condition.

    The ORDER BYclause in the subquery is

    not needed unless you are performing Top-

    N analysis.

    Use single-row operators with single-rowsub queries, and use multiple-row operators

    with multiple-row sub queries.

  • 8/11/2019 Centralized

    7/14

    Types of Subqueries

    Single-row subquery

    Multiple-row subquery

    Main query

    Subqueryreturns

    ST_CLERK

    ST_CLERK

    SA_MAN

    Main query

    Subquery

    returns

  • 8/11/2019 Centralized

    8/14

    Single-Row Subqueries

    Return only one row

    Use single-row comparison operators

    Operator Meaning

    = Equal to

    > Greater than

    >= Greater than or equal to

    < Less than

  • 8/11/2019 Centralized

    9/14

    SELECT last_name, job_id, salary

    FROM employees

    WHERE job_id =

    (SELECT job_id

    FROM employeesWHERE employee_id = 141)

    AND salary >

    (SELECT salary

    FROM employees

    WHERE employee_id = 143);

    Executing Single-Row Subqueries

    ST_CLERK

    2600

  • 8/11/2019 Centralized

    10/14

    SELECT last_name, job_id, salary

    FROM employees

    WHERE salary =

    (SELECT MIN(salary)

    FROM employees);

    Using Group Functions in a Subquery

    2500

  • 8/11/2019 Centralized

    11/14

    Multiple-Row Subqueries

    Return more than one row

    Use multiple-row comparison operators

    Operator Meaning

    IN Equal to any member in the list

    ANY Compare value to each value returned by the

    subquery

    ALL Compare value to every value returned by

    the subquery

  • 8/11/2019 Centralized

    12/14

    SELECT employee_id, last_name, job_id, salary

    FROM employees

    WHERE salary < ANY

    (SELECT salary

    FROM employeesWHERE job_id = 'IT_PROG')

    AND job_id 'IT_PROG';

    Using the ANYOperator

    in Multiple-Row Subqueries

    9000, 6000, 4200

  • 8/11/2019 Centralized

    13/14

    SELECT employee_id, last_name, job_id, salary

    FROM employees

    WHERE salary < ALL

    (SELECT salary

    FROM employeesWHERE job_id = 'IT_PROG')

    AND job_id 'IT_PROG';

    Using the ALLOperator

    in Multiple-Row Subqueries

    9000, 6000, 4200

  • 8/11/2019 Centralized

    14/14

    SELECT emp.last_name

    FROM employees emp

    WHERE emp.employee_id NOT IN

    (SELECT mgr.manager_id

    FROM employees mgr);

    no rows selected

    Null Values in a Subquery