Objectives In this lesson, you will learn to:

Slides:



Advertisements
Similar presentations
Database Systems: Design, Implementation, and Management Tenth Edition
Advertisements

Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Microsoft Access 2010 Chapter 7 Using SQL.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Introduction to SQL J.-S. Chou Assistant Professor.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
Chapter 2 Basic SQL SELECT Statements
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL.
ASP.NET Programming with C# and SQL Server First Edition
Using SQL Queries to Insert, Update, Delete, and View Data Date Retrieval from a single table & Calculations © Abdou Illia MIS Spring 2015.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
SQL/lesson 2/Slide 1 of 45 Retrieving Result Sets Objectives In this lesson, you will learn to: * Use wildcards * Use the IS NULL and IS NOT NULL keywords.
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.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
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 Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 CONACT UC:  Magnific training   
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
In this session, you will learn to: Manage databases Manage tables Objectives.
Restricting and Sorting Data
Retrieving Data Using the SQL SELECT Statement
Chapter 5 Introduction to SQL.
In this session, you will learn to:
Connect to SQL Server and run select statements
Relational Database Design
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Basic select statement
The Selection Structure
DB Implementation: MS Access Forms
Writing Basic SQL SELECT Statements
Retrieving Data Using the SQL SELECT Statement
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
DB Implementation: MS Access Forms
Restricting and Sorting Data
Contents Preface I Introduction Lesson Objectives I-2
Relational Database Design
Retrieving Data Using the SQL SELECT Statement
Restricting and Sorting Data
Restricting and Sorting Data
Presentation transcript:

Objectives In this lesson, you will learn to: Identify the features of client/server architecture Identify the input requirements for a query Plan and create a format for the query output Identify and use sources of data for a query Identify and use different types of queries Use the SELECT statement with logical operators

Getting Started Client/Server Architecture In this architecture, the functionality of the application is split between two processes: the client process and the server process The client process handles the data input and the user interface issues The server process performs all validations on the data

Getting Started (Contd.) Benefits of the two-tier model (Client/Server) model are: Data Sharing: Data is separated from the client side and is stored at a central location where all users have access to the data. Reduces duplication and maintenance: Since data is stored centrally, data maintenance is easy. There is no duplication of data and therefore no inconsistency in the data stored.

Getting Started (Contd.) Structured Query Language SQL Server provides the Structured Query Language (SQL) to access data objects from the server MS-SQL Server has added more features to the base-level syntax of SQL and has its own SQL called Transact-SQL (T-SQL)

Draft the query The SELECT Statement Enables you to access and retrieve data from a database Syntax: SELECT [ALL | DISTINCT] select_column_list [INTO [new_table_name]] [FROM {table_name | view_name} [(optimizer_hints)][[, {table_name2 | view_name2}[(optimizer_hints)] [WHERE clause] [GROUP BY clause][HAVING clause] [ORDER BY clause][COMPUTE clause] [FOR <expr>]

Draft the query (Contd.) Using Literals The result set of a data query statement can be made more readable by including a string called a literal in the SELECT list Literals are enclosed in single quotes and get printed exactly as they are written in the SELECT list

Execute the query Action: Connect to the server Connect to the database Method 1: Choose the database () from the SQL Query Analyzer database drop-down list Method 2: In the Query Analyzer window, type: USE DATABASE

Execute the query (Contd.) In the Query Analyzer window, type the query: Execute the query Click the Execute option from the Query menu on the menu bar or Click the Execute button on the toolbar

Verify that the query output is as per the required results Check whether: The required columns are displayed

Displaying Specific Columns With User-Friendly Column Headings

Task List Draft the query Execute the query Verify that the query output is as per the required results

Draft the query Displaying Columns With User-Defined Headings Syntax Method 1: SELECT column_heading=column_name[,column name…] FROM table_name Method 2: SELECT column_name column_heading [,column_name…] FROM table_name

Displaying Selected Rows From a Table

Task List Create a format for the query output Draft the query Execute the query Verify that the query output is as per the required results

Draft the query The SELECT…WHERE Statement Retrieves and displays data with a specific condition Syntax SELECT column_list FROM table_name WHERE search_condition

Arithmetic Operators SQL Server supports operators that perform arithmetic operations such as addition, subtraction, division, and multiplication on numeric columns The arithmetic operators supported by SQL Server are: + (for Addition) - (for Subtraction) / (for Division) * (for Multiplication) % (for Modulo)

Arithmetic Operators (Contd.) Some rules regarding the use of arithmetic operators are: Arithmetic operations can be performed on numeric columns or numeric constants The Modulo (%) operator cannot be used with columns of money, smallmoney, float, or real datatypes

Arithmetic Operators (Contd.) Operator Precedence When multiple arithmetic operators are used in a single query, the processing of the operation takes place according to the precedence of arithmetic operators The precedence level of arithmetic operators in an expression is multiplication (*), division (/), modulo (%) followed by subtraction (-) and addition (+) The precedence of the operators can be changed by using the primary grouping object called parentheses (())

Search Based on Conditions SQL Server provides a few methods for searching rows in a table. These methods can be broadly categorized as follows: Logical operators Comparison operators Range operators List operators

Draft the query Logical Operator - Multiple search conditions can be combined by using the following logical operators: ORreturns the result when any of the specified search conditions is true ANDreturns the result when all the specified search conditions are true NOT neutralizes the expression that follows it When more than one logical operator is combined in the WHERE clause, the order of precedence is NOT, AND, and OR Parentheses can be used to change the logical order of precedence

Draft the query (Contd.) Syntax SELECT column_list FROM table_name WHERE conditional_expression {AND/OR}[NOT] conditional_expression

More on Operators Apart from logical operators, SQL Server also supports the following operators: Comparison Operators Range Operators List Operators

More on Operators (Contd.) Comparison Operators Comparison operators allow row retrieval from a table based on the condition specified in the WHERE clause Syntax SELECT column_list FROM table_name WHERE expression1 comparison_operator expression2

More on Operators (Contd.) Range Operators The range operator is used to retrieve data that can be extracted in ranges. The range operators are: BETWEEN NOT BETWEEN Syntax SELECT column_list FROM table_name WHERE expression1 range_operator expression2 AND expression3

More on Operators (Contd.) List Operators The IN operator allows the selection of values that match any one of the values in a list The NOT IN operator restricts the selection of values that match any one of the values in a list Syntax SELECT column_list FROM table_name WHERE expression list_operator (‘value_list‘)

Summary In this lesson, you learned that: A database management system consists of a Server, a database (or multiple databases) with tables containing data, and a client (front-end) that helps a user interact with the server to retrieve data. The language provided by SQL Server to access data from a database is known as Structured Query Language (SQL). Microsoft SQL Server provides a customized implementation of SQL called T-SQL.

Summary (Contd.) SQL Server provides a SELECT statement to access and retrieve data from a database. The SELECT statement queries the server to prepare a result and return it to the client application. The SELECT statement can be used to retrieve specific column(s) from the table by specifying the column names from the table. The SELECT statement along with the asterisk (*) symbol produces the result that contains the details of all the columns in the table.

Summary (Contd.) The order of the columns can be changed in the result set of the SELECT statement by specifying the individual column names separated by a comma. SQL Server provides two methods for specifying the column heading. In the first method, the column heading is specified before the column name whereas in the second method, the column name is specified before the column heading. The WHERE clause is provided by SQL Server to specify the condition to retrieve specific data. The result set of the data query statement can be made more readable by including a string called literals in the SELECT list.

Summary (Contd.) SQL Server supports operators that perform arithmetic operations like addition, subtraction, division, and multiplication on numeric columns. In a mixed mode arithmetic operation, the lower datatype value gets converted into a higher datatype value according to datatype precedence. SQL Server provides the following set of operators: Logical operators like AND, OR and NOT Comparison operators like =, >, <, >=, <=, ! =, !< and !> Range operators like BETWEEN and NOT BETWEEN List operators like IN and NOT IN