m_09_1.00 managing schema objects with demos and labs 2012.pdf

Upload: edmundo-lozada

Post on 02-Apr-2018

224 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    1/13

    Module 9: ManagingSchema Objects

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    2/13

    Overview

    Naming guidelines for identifiers in schema objectdefinitions

    Storage and structure of schema objects

    Implementing data integrity using constraints

    Implementing business rules at the database level usingtriggers and sequences

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    3/13

    Identifiers and Naming

    Object names and column names are not case sensitivein Oracle, but are sorted in the data dictionary in uppercase unless forced to be case sensitive using delimiters

    Object and column names are stored in system catalog

    in the same case as specified in the DDLIn Oracle and SQL Server, object names have to beunique within the same schema

    Defining schemas and ownership differ very slightly

    between Oracle and SQL Server

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    4/13

    Managing Tables

    There is a generictable definition syntaxin Oracle and SQLServer

    There are varioustypes of tables inOracle and SQL Server

    Components ofcolumn definition are

    column name, datatype, default valueand constraints(optional)

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    5/13

    Managing Constraints

    Types of constraints found in Oracle and SQL Server are: NOT NULL

    CHECK

    UNIQUE

    PRIMARY KEY FOREIGN KEY

    Constraints can be definedin-line with column definition or out-of-line as table constraints

    Constraints on single columns can be defined as column

    constraints or table constraints, and multi-column constraints aredefined as table constraints

    Primary key constraints are enforced using unique indexes and NOTNULL constraints in both Oracle and SQL Server

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    6/13

    Demonstration 1: Referential Integrity via Constraints

    In this demonstration you will see how to:

    Define a table with a Primary Key

    Validate with Foreign Keys

    Insert data and view an exception and asuccess

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    7/13

    Managing Triggers

    SQL Server INSTEAD OF triggerssimilar to BEFORE triggers in Oracle

    SQL Server triggers are at the statement level

    Oracle uses

    pseudo-row structures:new and :old

    SQL Server - pseudo-tablesDELETED and INSERTED

    Unlike Oracle, SQL Servercan define First and LastTrigger in a set.

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    8/13

    Demonstration 2: Referential Integrity via Triggers

    In this demonstration you will see how to:

    Define a trigger

    Validate and auto commit or rollbacktransaction (insert)

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    9/13

    Managing Indexes

    Unique and non-unique non-clustered B-tree indexes arefound in both Oracle and SQL Server

    SQL Server clustered indexes are similar to Oracleindex-organized tables

    SQL Server indexes can be created, dropped, rebuilt, orreorganized offline or online

    SQL Server provides indexing on XML and Spatial datatypes

    SQL Server 2012 includes xVelocity memory optimizedcolumnstore indexes to speed up data warehousingqueries

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    10/13

    Demonstration 3: Create and Maintain Indexes

    In this demonstration you will see how to:Create an Included Index with SSMS

    Compare execution plans and results

    Create the Included Index with T-SQL

    Rebuild the Index

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    11/13

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    12/13

    Demonstration 4: Create indexed view

    Demonstration:

    Create indexed view

  • 7/27/2019 M_09_1.00 Managing Schema Objects with Demos and Labs 2012.pdf

    13/13

    Review

    We learned how Oracle and SQL Server differ in theinterpretation of identifier names in schema objectdefinitions

    We compared types of tables and indexes found in

    Oracle and SQL Server and learned how to create andmaintain them

    We went over the differences in selection of storageparameters between Oracle and SQL Server

    We compared other schema objects in Oracle and SQLServer such as constraints, triggers, views andsequences and learned how to manage them