Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object...

13
Module 9: Managing Schema Objects

Transcript of Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object...

Page 1: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Module 9:Managing Schema Objects

Page 2: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Overview

Naming guidelines for identifiers in schema object definitions

Storage and structure of schema objects

Implementing data integrity using constraints

Implementing business rules at the database level using triggers and sequences

Page 3: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Identifiers and Naming

Object names and column names are not case sensitive in Oracle, but are sorted in the data dictionary in upper case 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 DDL

In Oracle and SQL Server, object names have to be unique within the same schema

Defining schemas and ownership differ very slightly between Oracle and SQL Server

Page 4: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Managing Tables

There is a generic table definition syntax in Oracle and SQL Server

There are various types of tables in Oracle and SQL Server

Components of column definition are column name, data type, default value and constraints (optional)

Page 5: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Managing Constraints

Types of constraints found in Oracle and SQL Server are:

• NOT NULL• CHECK• UNIQUE• PRIMARY KEY• FOREIGN KEY

Constraints can be defined in-line with column definition or out-of-line as table constraintsConstraints on single columns can be defined as column constraints or table constraints, and multi-column constraints are defined as table constraintsPrimary key constraints are enforced using unique indexes and NOT NULL constraints in both Oracle and SQL Server

Page 6: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

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 a success

Page 7: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Managing Triggers

SQL Server INSTEAD OF triggers similar to BEFORE triggers in Oracle

SQL Server triggers are at the statement level

Oracle uses – pseudo-row structures :new and :old

SQL Server - pseudo-tables DELETED and INSERTED

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

Page 8: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Demonstration 2: Referential Integrity via Triggers

In this demonstration you will see how to:

Define a trigger

Validate and auto commit or rollback transaction (insert)

Page 9: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Managing Indexes

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

SQL Server clustered indexes are similar to Oracle index-organized tables

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

SQL Server provides indexing on XML and Spatial data types

Page 10: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

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

Page 11: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Demonstration 4: Partitioned Index

In this demonstration you will see how to:

Define a partition function

Define a partition scheme

Assign an Index to a partition scheme

Rebuild an Index for a single partition

Page 12: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Managing Views

Oracle views can be created even with lack of permissions or absence of the base objects, using FORCE clause

In SQL Server definition of the view can be stored in “encrypted” form in the system catalog

Oracle views can be defined with constraints and can be read-only

WITH CHECK OPTION is found in both DBMSs

Page 13: Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.

Review

We learned how Oracle and SQL Server differ in the interpretation of identifier names in schema object definitions

We compared types of tables and indexes found in Oracle and SQL Server and learned how to create and maintain them

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

We compared other schema objects in Oracle and SQL Server such as constraints, triggers, views and sequences and learned how to manage them