In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
With Microsoft Access 2010© 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Chapter 4B: More Advanced PL/SQL Programming
The SQL Query Language DML1 The SQL Query Language DML Odds and Ends.
Concepts of Database Management Sixth Edition
Database Systems More SQL Database Design -- More SQL1.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Chapter 9: Creating Database Conventions & Standards MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
Topics Views Stored Procedures User Defined Functions Triggers.
Introduction to SQL Structured Query Language Martin Egerhill.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
Module 12 Handling Errors in T-SQL Code. Module Overview Understanding T-SQL Error Handling Implementing T-SQL Error Handling Implementing Structured.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Introduction to Databases Chapter 7: Data Access and Manipulation.
Chapter 6 Additional Database Objects
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Views: Limiting Access to Data A view is a named select statement that is stored in a database as an object. It allows you to view a subset of rows or.
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
Stored Procedures, Transactions, and Error-Handling
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
Objectives Database triggers and syntax
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Search Overview Search Features: WSS and Office Search Architecture Content Sources and.
Slide 1 of 19Session 13 Ver. 1.0 Querying and Managing Data Using SQL Server 2005 In this session, you will learn to: Implement stored procedures Implement.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Working with SQL Server Database Objects Faculty: Nguyen Ngoc Tu.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
SQL Server 2012 Session: 1 Session: 12 Triggers Data Management Using Microsoft SQL Server.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
Stored Procedures / Session 4/ 1 of 41 Session 4 Module 7: Introducing stored procedures Module 8: More about stored procedures.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
SQL Triggers, Functions & Stored Procedures Programming Operations.
 CONACT UC:  Magnific training   
1 Stored Procedure, Function and Trigger. 2Objectives 1. Database Programming 2. Stored Procedure 3. Function 4. Trigger.
In this session, you will learn to: Understand managed code Create managed database objects Define the Hypertext Transfer Protocol endpoints Implement.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
Slide 1 of 32ASH-Training Querying and Managing Data Using SQL Server 2014 By: Segla In this session, you will learn to: Query data by using joins Query.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
SQL Basics Review Reviewing what we’ve learned so far…….
1. Advanced SQL Functions Procedural Constructs Triggers.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
In this session, you will learn to: Manage databases Manage tables Objectives.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
PROCEDURES, CONDITIONAL LOGIC, EXCEPTION HANDLING, TRIGGERS
Module 7: Implementing Views
PT2520 Unit 9: Database Security II
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Contents Preface I Introduction Lesson Objectives I-2
Prof. Arfaoui. COM390 Chapter 9
Objectives In this lesson, you will learn to:
Presentation transcript:

In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives

A View is: Used to view data from tables Similar to creating tables but it does not contain any data as it derives its data from the underlying tables Created by using CREATE VIEW statement Syntax: CREATE VIEW view_name [(column_name [, column_name]...)] [WITH ENCRYPTION] [, SCHEMABINDING]] AS select_statement [WITH CHECK OPTION] Let’s see how… Creating Views

Indexing of Views: Is done when the volume of data in the underlying table is large and not updated frequently Improves query performance Is performed by creating an unique clustered index on a view and afterwards nonclustered index can also be created Is performed by using CREATE INDEX statement Let’s see how… Indexing Views

Just a minute In which of the following conditions will you NOT create an indexed view: 1.When the data is large 2.When the data is regularly updated 3.When you need to improve the performance of the view Answer: 2.When the data is regularly updated

Managing a view involves altering, dropping, or renaming. Altering a view involves modifying a view without dropping it. Syntax: ALTER VIEW view_name [(column_name)] WITH ENCRYPTION] AS select_statement WITH CHECK OPTION] Dropping a view involves deleting the view when it is no longer required. Syntax: DROP VIEW view_name Managing Views

Renaming the name of the view without deleting it. Syntax: sp_rename old_viewname, new_viewname Let’s see how… Managing Views (Contd.)

Problem Statement: You are a database developer at AdventureWorks, Inc. You need to frequently generate a report containing the following details of the employees: Employee ID Employee First Name Employee Last Name Title Manager First Name Manager Last Name Demo: Creating Views

Problem Statement (Contd.): To retrieve this data, you need to execute the following statement on the database: SELECT e1.EmployeeID, c1.FirstName, c1.LastName, e1.Title, c2.FirstName AS [Manager First Name],c2.LastName AS [Manager Last Name] FROM HumanResources.Employee e1 INNER JOIN Person.Contact c1 ON e1.ContactID = c1.ContactID INNER JOIN HumanResources.Employee AS e2 ON e1.ManagerID = e2.EmployeeID INNER JOIN Person.Contact AS c2 ON e2.ContactID = c2.ContactID Demo: Creating Views (Contd.)

Problem Statement (Contd.): As a database developer, you need to simplify the execution of this query so that you do not need to send such a large query to the database engine every time the report is required. Demo: Creating Views (Contd.)

Solution: To solve the preceding problem, you need to perform the following tasks: 1.Create a view. 2. Verify the simplification of the query execution. Demo: Creating Views (Contd.)

Full-Text Search: Allows you to perform complex search on the data Allows you to search for synonyms or antonyms of a particular word Feature is disabled by default To retrieve the required details by using full-text, you need to perform the following tasks: 1.Enable the full-text search in the database. 2.Create a full-text catalog. 3.Create a unique index. 4.Create a full-text index. 5.Populate the full-text index. Let’s see how… Configuring Full-Text Search

To search using full-text index, use the following full-text predicates: FREETEXT: Searches for any variation of a word or a group of words given in the search column. CONTAINS: Searches for a specific phrase, for the proximity of words within a text or for the exact match. Let’s see how… Searching Data by Using a Full-Text Search

Just a minute List the types of full-text index population methods. Answer: The three types of full-text index population methods are: 1.Full population 2.Change tracking based population 3.Incremental timestamp based population

Just a minute Which predicate is used to search for a specific phrase or for an exact match? Answer: CONTAINS

Problem Statement: The users at AdventureWorks, Inc. need to frequently search for employees, customers, or vendors based on the location. The location details of all these entities are stored in the Address table in the Person schema. The users want to search for addresses with different combinations of the words specified in the search criteria. For example, they need to search for the locations that contain the words ‘Santa’ and ‘drive’ in the AddressLine1 column. Similarly, they might need to search for the locations that contain the words ‘Santa’ and ‘Street’ in the AddressLine1 column. How will you enable the users to perform such a data search? Demo: Implementing Full-Text Search

Solution: To solve the preceding problem, you need to perform the following tasks: 1.Enable the Full-text search on the AdventureWorks database. 2.Create a default full-text catalog. 3.Create a full-text index. 4.Search the data by using the CONTAINS predicate. Demo: Implementing Full-Text Search (Contd.)

Batch: Is created to send a group of SQL statements together to SQL Server for execution Compiles the statements as a single executable unit called an execution plan Uses GO command at the end to send the SQL statements to the instance of SQL Server Uses variables to store values. They are: Local variables Global variables Uses PRINT statement to display user-defined messages and values of variables Let’s see how… Creating Batches

Just a minute Which of the following statements can be used within a batch? 1.CREATE FUNCTION 2.CREATE RULE 3.DECLARE Answer: 3.DECLARE

Allow batches to perform conditional execution of statements with the following control-of-flow statements: IF…ELSE statement CASE statement WHILE statement Using Constructs

IF…ELSE statement: Performs a particular action based on the result of the boolean expression Syntax: IF boolean_expression {sql_statement | statement_block} [ELSE boolean_expression {sql_statement | statement_block}] Let’s see how… Using Constructs (Contd.)

CASE statement: Evaluates a list of conditions and returns one of the various possible results Syntax: CASE WHEN boolean_expression THEN expression [[WHEN boolean_expression THEN expression] [...]] [ELSE expression] END Let’s see how… Using Constructs (Contd.)

WHILE statement: Executes a batch repeatedly as long as the given condition holds true Uses BREAK and CONTINUE statements to break the loop or to continue the loop Syntax: WHILE boolean_expression {sql_statement | statement_block} [BREAK] {sql_statement | statement_block} [CONTINUE] Let’s see how… Using Constructs (Contd.)

Errors in SQL Server can be handled on two levels: Using the TRY-CATCH construct Using the RAISERROR statement Handling Errors and Exceptions

TRY-CATCH construct is used in the following way: Try block encloses a group of T-SQL statements. If any error occurs in the statements of TRY block, control passes to the CATCH block. CATCH block encloses another group of statements, which gets executed when an error occurs. Let’s see how… Handling Errors and Exceptions (Contd.)

RAISERROR: Is used to return messages back to the called applications Uses the same message format as a system error or warning message generated by the SQL Server Database Engine Can also return user-defined error messages Let’s see how… Handling Errors and Exceptions (Contd.)

Just a minute Which system function returns the text of the error message when used in the CATCH block? Answer: ERROR_MESSAGE()

Just a minute How can you return a user-defined error message in a batch? Answer: Using the RAISERROR statement

In this session, you learned that: A view is a virtual table, which derives its data from one or more tables known as the base or underlying tables. Views serve as security mechanisms, thereby protecting data in the base tables. The SQL Server allows data to be modified only in one of the underlying tables when using views, even if the view is derived from multiple underlying tables. The SQL Server enables users to search for a wide range of text in the SQL tables through a full-text query feature. You can enable the full-text search by using the command, SP_FULLTEXT_DATABASE ENABLE. A full-text catalog can be created by using the CREATE FULLTEXT CATALOG statement. Summary

A full-text index can be created by using the CREATE FULLTEXT INDEX statement. Three types of full-text population methods are full population, change tracking-based population, and incremental timestamp-based population. Full-text predicates that can be used to perform full-text search are CONTAINS and FREETEXT. A FREETEXT predicate searches for any variation of a word or a group of words given in the search column. The CONTAINS predicate searches for a specific phrase or for the exact match. A batch is a set of SQL statements submitted together to the server for execution. You can use a variable to store a temporary value. Summary (Contd.)

You can use the PRINT statement to display a user-defined message or the content of a variable on the screen. You can use the comment entries in batches to write a description of the code. You can use the IF…ELSE statement for conditional execution of the SQL statements. The CASE statement evaluates a list of conditions and returns one of the various possible results. You can use the WHILE statement in a batch to allow a set of T-SQL statements to execute repeatedly as long as the given condition holds true. The BREAK statement causes an exit from the WHILE loop. Summary (Contd.)

The CONTINUE statement causes the WHILE loop to restart, skipping any statements after the CONTINUE statement within the loop. Two ways to handle errors in batches are: TRY-CATCH construct RAISERROR statement