RDBMS Conceptss

download RDBMS Conceptss

of 49

Transcript of RDBMS Conceptss

  • 7/29/2019 RDBMS Conceptss

    1/49

    1

    RDBMS Concepts

  • 7/29/2019 RDBMS Conceptss

    2/49

    2

    Database

    Database is an organized collection of data.

    Collection ofrecords stored in a systematic way.

    Organized for Better Retrieval and Sorting.

    http://en.wikipedia.org/wiki/Database_recordhttp://en.wikipedia.org/wiki/Database_record
  • 7/29/2019 RDBMS Conceptss

    3/49

    3

    Types of Database Models

    Hierarchical model - Data is organized into a tree-like

    structure

    Network model - Uses recordsand sets. Records contain

    fields, sets define man-many relationships.

    Relational model Geared for OLTP

    Dimensional Model Geared for Datawarehousing

    Object Relational Model Object Oriented Features

  • 7/29/2019 RDBMS Conceptss

    4/49

    4

    Basic Constructs

    Tables

    Columns

    Constraints

    Indexes

    Views

    Procedures

    SQL

  • 7/29/2019 RDBMS Conceptss

    5/49

    5

    Table & Columns

    In a relational database and SQL databases a table is a set of

    data elements (values) that is organized using a model ofhorizontal rows and vertical columns.

    Columns form the attributes of a table. A table consists of

    one or more columns. Every RDBMS has a restriction on themax columns.

    Eg: Oracle allows 1000 columns per table

    http://en.wikipedia.org/wiki/Relational_databasehttp://en.wikipedia.org/wiki/SQL_databasehttp://en.wikipedia.org/wiki/Row_%28database%29http://en.wikipedia.org/wiki/Column_%28database%29http://en.wikipedia.org/wiki/Column_%28database%29http://en.wikipedia.org/wiki/Row_%28database%29http://en.wikipedia.org/wiki/SQL_databasehttp://en.wikipedia.org/wiki/Relational_database
  • 7/29/2019 RDBMS Conceptss

    6/49

    6

    Primary Key

    Primary key is a value that can be used to identify a unique

    row in a table.

    Primary key is a candidate key chosen as the main method of

    uniquely identifying a tuple in a relation.

    Natural Key Key as understood by Business Eg: Associate

    Id

    Surrogate Key Non Business Key Eg : Sequence Number

  • 7/29/2019 RDBMS Conceptss

    7/497

    Primary Key..

    Should be immutable, its value should not be changed

    during the course of normal operations of the database.

    Candidate keys uniquely identifying a row but are likely not

    to be immutable.

    Primary key should generally be short to minimize data

    stored by relations.

    Can be a compound consisting on multiple columns.

  • 7/29/2019 RDBMS Conceptss

    8/49

    8

    Foreign Keys

    A field or group of fields that point to a key field or group of

    fields usually in a different table.

    In scenarios where a foreign key refers to the same table

    itself it is a self key.

    Ensures Data Integrity

    Eg : Employee Belonging to a Department

  • 7/29/2019 RDBMS Conceptss

    9/49

    9

    Foreign Keys Example

    ASSOCIATE ID

    FIRST NAME

    LAST NAME

    DEPT NO

    EmployeeDEPT NO

    DEPT NAME

    Department

  • 7/29/2019 RDBMS Conceptss

    10/49

    10

    Not Nul ls

  • 7/29/2019 RDBMS Conceptss

    11/49

    11

    Constraint - Not Nul l

    Enforces the need for data to be mandatory.

    Applied at column level.

    Record cannot be created if value is not supplied.

    Eg: First Name is mandatory.

  • 7/29/2019 RDBMS Conceptss

    12/49

    12

    Constraint - Check

    Enforces the values entered are from a fixed List of Values.

    Valid only when a fixed list is present and action is more for

    validation.

    For variable list a Master Detail with Foreign Keys must be

    used.

    Eg: A flag indicating the gender M or F.

  • 7/29/2019 RDBMS Conceptss

    13/49

    13

    Defaults

    Provides for a default value when none is provided.

    Useful when user wants to avoid specifying a value every

    time.

    Eg: Default the date to todays date.

  • 7/29/2019 RDBMS Conceptss

    14/49

    14

    Defaults

  • 7/29/2019 RDBMS Conceptss

    15/49

    15

    I ndexes

    Feature in a database that allows quick access to the rows in

    a table.

    Smaller than the original table.

    Optimized for quick searching.

    Eg : Search on the name of an associate

  • 7/29/2019 RDBMS Conceptss

    16/49

    16

    SQL Select

    Structured Query Language

    Way to access data.

    Uses simplified English

    SQL is a database access, nonprocedural language. Users describe

    in SQL what they want done, and the SQL language compiler

    automatically generates a procedure to navigate the database andperform the desired task.

    Eg: Get all the employess

    Select * from emplo yee

  • 7/29/2019 RDBMS Conceptss

    17/49

    17

    SQL Select.

    Get all employees whose salary > 5000

    Select * from employee where salary > 5000

    Get associate id and first name

    Select associate_id,first_name from employee

  • 7/29/2019 RDBMS Conceptss

    18/49

    18

    Samples of Select

  • 7/29/2019 RDBMS Conceptss

    19/49

    19

    SQL Standards

    ANSI SQL

    The American National Standards Institute (ANSI) has

    established a set of industry standards for SQL.

    Set of standards which SQL language must be complainant

    with.

    Database vendors introduce non ANSI complaint features.

    Reduction in portability due to non-compliance.

  • 7/29/2019 RDBMS Conceptss

    20/49

    20

    SQL Joins

    Combines records from two or more tables in a relational

    database.

  • 7/29/2019 RDBMS Conceptss

    21/49

    21

    Cross Join

    A cross join returns the cartesian product of the sets of rows fromthe joined tables.

    While not used commonly, a cross join is the foundation uponwhich inner joins are built.

    SELECT *

    FROM emplo yee CROSS JOIN departm ent;

    SELECT *

    FROM emplo yee,department;

  • 7/29/2019 RDBMS Conceptss

    22/49

    22

    I nner Join

    Intersection between the two tables

    SELECT * FROM emplo yee ,departmen tWHERE emp loy ee.DepartmentID = departm ent.Departm entID

    L ft t j i

  • 7/29/2019 RDBMS Conceptss

    23/49

    23

    Left outer join

    Instead of limiting results to those in both tables, it limits

    results to those in the "left" table

    SELECT * FROM employee LEFT OUTER JOIN department ON

    employee.DepartmentID = department.DepartmentID

    Ri ht t j i

  • 7/29/2019 RDBMS Conceptss

    24/49

    24

    Right outer join

    Much like a left outer join, except that the tables are reversed

    SELECT * FROM emp loy ee RIGHT OUTER JOIN departm ent ON

    emp loy ee.DepartmentID = department.Departm entID

    F ll t j i

  • 7/29/2019 RDBMS Conceptss

    25/49

    25

    Ful l outer join

    Combines the results of both left and right outer joins.

    SELECT * FROM employ ee FULL OUTER JOIN department ON

    emp loy ee.DepartmentID = department.Departm entID

  • 7/29/2019 RDBMS Conceptss

    26/49

    26

    SQL I nserts

    Adds a record to a table in a relational database.

    INSERT INTO table (column1, [co lum n2, ... ]) VALUES (value1,

    [value2, ...])

    Eg: INSERT INTO phone_book (name, number) VALUES ('JohnDoe', '555-1212');

  • 7/29/2019 RDBMS Conceptss

    27/49

    27

    SQL Updates

    Updates an existing record from a table in a relational

    database.

    Eg: Update phone_book set name = John Davis where name

    ='John Doe';

  • 7/29/2019 RDBMS Conceptss

    28/49

    28

    SQL Delete

    Deletes an existing record from a table in a relational

    database.

    Eg: Delete phone_book where name = John Davis

  • 7/29/2019 RDBMS Conceptss

    29/49

    29

    Commit/Rollback

    Signifies the end of a transaction unit.

    Commit Means finalize and write all these changes to the

    database.

    Rollback Revert back all changes made to the database.

    Valid from the point when the last commit/rollback was

    issued.

  • 7/29/2019 RDBMS Conceptss

    30/49

    30

    Transaction

  • 7/29/2019 RDBMS Conceptss

    31/49

    31

    SQL Types

    DML Data Manipulation Language

    Changes to Data

    Eg: Selec t, Ins ert, Upd ate, Delete

    DDL

    Data Definition Language

    Changes to structure

    Eg: Create Table

  • 7/29/2019 RDBMS Conceptss

    32/49

    32

    Sample Create Table

    CREATE TABLE EMP

    (

    EMPNO NUMBER(9),

    ENAME VARCHAR2(10 BYTE),

    JOB VARCHAR2(9 BYTE),

    MGR NUMBER(4),

    HIREDATE DATE,

    SAL NUMBER(7,2),

    COMM NUMBER(7,2),

    DEPTNO NUMBER(2) );

    CREATE UNIQUE INDEX PK_EMP ON EMP

    (EMPNO);

    ALTER TABLE EMP ADD (

    CONSTRAINT PK_EMP PRIMARY KEY (EMPNO));

    ALTER TABLE EMP ADD (

    CONSTRAINT FK_DEPTNO FOREIGN KEY (DEPTNO)

    REFERENCES DEPT (DEPTNO));

  • 7/29/2019 RDBMS Conceptss

    33/49

    33

    Triggers

    Applicable to a table. Way to enforce complex integrity rules

    which cannot be implemented by constraints.

    Consists of a SQL statements along with procedural

    constructs.

    Get fired when the relevant condition is met, irrespective of

    the source of the transaction.

  • 7/29/2019 RDBMS Conceptss

    34/49

    34

    Stored Procedures

    A procedure orfunction is a object that consists of a set of

    SQL statements, grouped together, stored in the database

    Contains business logic and/or complex logic which cannot

    be done by simple SQL

    Procedures and functions let you combine the ease and

    flexibility of SQL with the procedural functionality of a

    structured programming language.

  • 7/29/2019 RDBMS Conceptss

    35/49

    35

    Views

    Tailored presentation of the data contained in one or more

    tables or other views.

    Can be thought of as a stored query or a virtual table.

    Eg: The emp loyees table has several co lumns and num erous

    rows of information. If you want users to see only f ive of these

    colum ns or on ly speci f ic rows, then yo u can create a view of

    that table.

  • 7/29/2019 RDBMS Conceptss

    36/49

    36

    Sample View

  • 7/29/2019 RDBMS Conceptss

    37/49

    37

    Security

    Schema Level Security Login

    Object Level Security Tables, Views etc

  • 7/29/2019 RDBMS Conceptss

    38/49

    38

    ACID

    Refers to Atomicity, Consistency, Isolation and Durability.

    Key properties of any DBMS without which integrity of the

    database cannot be guaranteed.

    Terms relevant to wrt a Transaction

    Transaction is a single logical operation

    Eg : Transfer of Funds (con sists o f mu l t ip le steps)

    A i i

  • 7/29/2019 RDBMS Conceptss

    39/49

    39

    Atomicity

    Guarantee that either all of the tasks of a transaction are

    performed or none of them are.

    Transfer of funds can be completed or it can fail for a

    multitude of reasons, but atomicity guarantees that one

    account won't be debited if the other is not credited as well.

    C i t

  • 7/29/2019 RDBMS Conceptss

    40/49

    40

    Consistency

    Database maintains it state when the transaction begins and

    when it ends.

    Transaction cannot break the rules, orin tegr i ty con straints,

    of the database.

    If an integrity constraint states that all accounts must have a

    positive balance, then any transaction violating this rule will

    be aborted.

    I l ti

  • 7/29/2019 RDBMS Conceptss

    41/49

    41

    Isolation

    Ability to make operations in a transaction appear isolated

    from all other operations.

    No operation outside the transaction can ever see the data in

    an intermediate state.

    Transferred funds can be seen on one account or the other,

    but never on botheven if the query runs while the transfer

    was still being processed.

    D bilit

  • 7/29/2019 RDBMS Conceptss

    42/49

    42

    Durability

    Guarantee that once the user has been notified of success,

    the transaction will persist, and not be undone.

    It will survive system failure, the database has checked the

    integrity constraints and won't need to abort the transaction.

    A hit t O l

  • 7/29/2019 RDBMS Conceptss

    43/49

    43

    ArchitectureOracle

    P A hit t O l

  • 7/29/2019 RDBMS Conceptss

    44/49

    44

    Process Architecture - Oracle

    C D t b i M k t

  • 7/29/2019 RDBMS Conceptss

    45/49

    45

    Common Databases in Market

    Oracle

    SQL Server

    DB2

    Teradata

    Sybase

    My SQL

    G A i t

  • 7/29/2019 RDBMS Conceptss

    46/49

    46

    Group Assignments

    Gather Information On ..

    Supplier

    Current Release

    Company Stability

    Support Infrastructure

    Cost Criteria

    Operating System Support

    Technical Features

    Market Penetration

    Group Presentations

  • 7/29/2019 RDBMS Conceptss

    47/49

    47

    Group Presentations

    General Information

    Each Group will be required to give a 15-30 minute formal presentationon their chosen topic.

    Except for software reviews all research MUST consist of at least three

    sources and EVERY GROUP WILL PROVIDE A BIBLIOGRAPHY OF

    THEIR REFERENCES at the time of presentation.

    Include your thoughts throughout the presentation. NOT just a

    short summation at the end.

    Fully discuss topic. For example, do not try to discuss all of Oracle

    Designer, take a part of it, like the Server Model, or ERD function.

    For topics that fall under number 2 and 3, use your own personal

    observations.

    Group Presentations (2)

  • 7/29/2019 RDBMS Conceptss

    48/49

    48

    Group Presentations (2)

    Possible Topics

    1. A subject scheduled to be discussed in class

    2. Personal review of a database design tool such as Power Designer,Oracle Designer, ER-Win etc.

    3. Review of a database system such as Oracle, Sybase, I nformix, etc.

  • 7/29/2019 RDBMS Conceptss

    49/49

    Questions and Answers