Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft SQL Server 2014 for Oracle DBAs Module 7

Similar presentations


Presentation on theme: "Microsoft SQL Server 2014 for Oracle DBAs Module 7"— Presentation transcript:

1 Microsoft SQL Server 2014 for Oracle DBAs Module 7
11: Monitoring and performance tuning Microsoft SQL Server 2014 for Oracle DBAs Module 7 Managing schema objects

2 Managing indexes and views
Module Overview 8: Managing schema objects Managing indexes and views

3 Lesson 1: Managing tables, constraints, object identifiers, and naming
8: Managing schema objects Demonstration: Referential integrity via constraints

4 Object identifiers and naming
8: Managing schema objects 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

5 There is a generic table definition syntax in Oracle and SQL Server
Managing tables 8: Managing schema objects 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)

6 40074A Managing constraints 8: Managing schema objects 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 constraints Constraints on single columns can be defined as column constraints or table constraints, and multi-column constraints are defined as table constraints Primary key constraints are enforced using unique indexes and NOT NULL constraints in both Oracle and SQL Server

7 Demonstration: Referential integrity via constraints
8: Managing schema objects 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 Demonstration Steps Open a New Query window within SQL Server Management Studio and select the AdventureWorks2012 database. Enter the following script to disable and drop the existing constraint on SalesTaxType: USE [AdventureWorks2012] GO ALTER TABLE [Sales].[SalesTaxRate] NOCHECK CONSTRAINT [CK_SalesTaxRate_TaxType] DROP CONSTRAINT [CK_SalesTaxRate_TaxType] GOCreate a new table to allow dynamic addition of tax types: CREATE TABLE [Sales].[SalesTaxType]( [TaxType] [tinyint] NOT NULL, [Name] [dbo].[Name] NOT NULL CONSTRAINT [PK_SalesTaxType_TaxType] PRIMARY KEY CLUSTERED ( [TaxType] ASC ) ON [PRIMARY] Populate the table with row constructors indicating tax type: INSERT [Sales].[SalesTaxType] ([TaxType], [Name]) VALUES (1, 'State/Province Sales Tax'), (More notes on the next slide)

8 Lesson 2: Managing triggers
8: Managing schema objects Demonstration: Referential integrity via triggers

9 Trigger creation and maintenance
8: Managing schema objects 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 Server can define First and Last Trigger in a set.

10 Demonstration: Referential integrity via triggers
8: Managing schema objects In this demonstration you will see how to: Define a trigger Validate and auto commit or rollback transaction (insert) Demonstration Steps Open a New Query window and select the AdventureWorks2012 database. Enter the following script to drop the foreign key constraint we created in the last demo: ALTER TABLE [Sales].[SalesTaxRate] NOCHECK CONSTRAINT [FK_SalesTaxRate_SalesTaxType_TaxType] GO DROP CONSTRAINT [FK_SalesTaxRate_SalesTaxType_TaxType] GOCreate a trigger for inserts or deletes to the SalesTaxRate table to see if the inserted type exists in the SalesTaxType table: IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[Sales].[tIU_SalesTaxRate]')) DROP TRIGGER [Sales].[tIU_SalesTaxRate] CREATE TRIGGER [tIU_SalesTaxRate] ON [Sales].[SalesTaxRate] FOR INSERT, UPDATE AS BEGIN int = count(*) FROM inserted i (More notes on the next slide)

11 Lesson 3: Managing indexes and views
8: Managing schema objects Demonstration: Partitioned indexes

12 SQL Server provides indexing on XML and Spatial data types
Working with indexes 8: Managing schema objects 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 SQL Server 2014 includes in-memory optimized columnstore indexes to speed up data warehousing queries and compress data storage

13 Oracle views can be defined with constraints and can be read-only
Managing views 8: Managing schema objects 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

14 Demonstration: More on columnstore indexes
8: Managing schema objects In this demonstration you will see how to: Create a non-clustered columnstore index Work with a clustered columnstore index Demonstration Steps In Object Explorer, expand Databases, then AdventureWorks2012, and then Tables. Scroll down to the Production.ProductInventory table and expand that table. Right-click the Indexes folder and select New Index. Type IX_ProductInventory_Shelf_Bin in the new index name box, leave the index type set to non- clustered, and leave the Unique checkbox unchecked. Click the Add and select the Shelf and Bin columns from the column selection dialog. Review, but don’t change any of the options on the Options page. On the Included Columns page or tab, click Add and select the Quantity column from the column selection dialog. On the Storage page, select the AW2012Idx filegroup for the new index. Click OK to create the index. The non-unique, nonclustered index you just crated is useful in physical inventory processing. It allows the application to quickly look up inventory by Shelf and Bin values. We created a covered index. When a query consists only of the following columns: ProductID, Shelf, Bin, and Quantity in the statement, it receives benefits. This is possible without creating a larger index, where all the columns are stored at every level of the B-tree. Because the data is in the leaf level, we have fewer scans against the entire table. This is possible for a few reasons: Quantity was “Included” in the index ProductID is part of the primary key Primary keys are automatically included in other indexes Right-click the Production.ProductInventory table and choose Select Top 1000 Rows. It should generate the following query: /****** Script for SelectTopNRows command from SSMS ******/ SELECT TOP 1000 [ProductID] (More notes on the next slide)

15 Demonstration: Partitioned indexes
8: Managing schema objects 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 Demonstration Steps Open a New Query window and select the AdventureWorks2012 database. Enter the following script: CREATE PARTITION FUNCTION PF_ProductListPriceHistory(datetime) AS RANGE RIGHT FOR VALUES (' ',' ',' ',' ', ' ',' ',' ',' ', ' ',' ',' ',' ', ' ',' ') GOGenerate a Partition Scheme and associate it with the Partition Function. CREATE PARTITION SCHEME PS_ProductListPriceHistory PARTITION PF_ProductListPriceHistory TO ([PRIMARY], [2001Q3],[2001Q4],[2002Q1],[2002Q2], [2002Q3],[2002Q4],[2003Q1],[2003Q2], [2003Q3],[2003Q4],[2004Q1],[2004Q2], [2004Q3],[2004Q4]) GOOnce the partition function and scheme have been created, create the index using the following script: USE [AdventureWorks2012] GO CREATE NONCLUSTERED INDEX [IX_ProductListPriceHistory_StartDate_EndDate] ON [Production].[ProductListPriceHistory] (More notes on the next slide)

16 Managing indexes and views
Module Overview 8: Managing schema objects Managing indexes and views  Next up – Database security

17 © 2014 Microsoft Corporation. All rights reserved
© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt "Microsoft SQL Server 2014 for Oracle DBAs Module 7"

Similar presentations


Ads by Google