Professional Documents
Culture Documents
Querying Tables
Process Description
Parse Checks Syntax for Accuracy.
Resolve Validates that the names of the Objects are Present
Optimize Determines the indexes to use
Compile Translates the Query into an Executable Plan
Execute Submits Compiled requests for Processing and then
Run.
Select Statement
(8 row(s) affected)
Literals
pub_id pub_name
------ -------------------- ----------------------------------------
0736 Publishers Name is : New Moon Books
0877 Publishers Name is : Binnet & Hardley
1389 Publishers Name is : Algodata Infosystems
1622 Publishers Name is : Five Lakes Publishing
1756 Publishers Name is : Ramona Publishers
9901 Publishers Name is : GGG&G
9952 Publishers Name is : Scootney Books
9999 Publishers Name is : Lucerne Publishing
(8 row(s) affected)
Range Operator
advance title
--------------------- ------------------------------------------
2275.0000 Is Anger the Enemy?
2000.0000 Prolonged Data Deprivation: Four Case Studies
4000.0000 Emotional Security: A New Algorithm
4000.0000 Fifty Years in Buckingham Palace Kitchens
(4 row(s) affected)
List Operator
Select Column_list
From table_name
Where Column_name IN ( Value_list)
List Operators
Use pubs
select pub_name, city,state
from publishers
where state IN ('MA','DC')
(2 row(s) affected)
String Operator - Wildcard
SQL Server provides a Pattern-Matching method for string
expressions using LIKE Keyword with the Wildcard mechanism.
Wildcard Description
LIKE 'Mc%' searches for all strings that begin with the letters Mc (McBadden).
LIKE '%inger' searches for all strings that end with the letters inger (Ringer, Stringer).
LIKE '%en%' searches for all strings that contain the letters en anywhere in the string
(Bennet, Green, McBadden).
LIKE '_heryl' searches for all six-letter names ending with the letters heryl (Cheryl, Sheryl).
LIKE '[CK]ars[eo]n' searches for Carsen, Karsen, Carson, and Karson (Carson).
LIKE '[M-Z]inger' searches for all names ending with the letters inger that begin with any
single letter from M through Z (Ringer).
LIKE 'M[^c]%' searches for all names beginning with the letter M that do not have the letter
c as the second letter (MacFeather).
String Operator - Wildcard
SELECT phone
FROM authors
WHERE phone LIKE '415%‘
phone
------------
415 986-7020
415 548-7723
415 834-2919
415 658-9932
415 836-7128
415 585-4620
415 935-4228
415 843-2991
415 354-7128
415 534-9219
415 836-7128
SELECT phone
FROM pubs.dbo.authors
WHERE phone NOT LIKE '415%'
Or
SELECT phone
FROM pubs.dbo.authors
WHERE NOT phone LIKE '415%'
_ ( Underscore)
SELECT au_lname, au_fname, phone
FROM authors
WHERE au_fname LIKE ‘_heryl'
(2 row(s) affected)
[]
SELECT au_lname, au_fname, phone
FROM authors
WHERE au_fname LIKE '[CS]heryl'
(2 row(s) affected)
[]
SELECT au_lname, au_fname, phone
FROM authors
WHERE au_lname LIKE '[CK]ars[eo]n'
(2 row(s) affected)
UnKnown value
(2 row(s) affected)
ISNULL
title ytd_sales
---------------------------------------------------------- -----------
The Psychology of Computer Cooking 0
Net Etiquette 0
(2 row(s) affected)
Check Your Understanding.
Q.1. How Query is Processed.?
Q.2. What is the Purpose of SELECT Statement.?
Q.3. What is the difference between ALL and DISTINCT.?
Q.4. What is Column Alias.? What is the Advantage.?
Q.5. What is Literal and what is its purpose.?
Q.6. What are Range Operators and what is the Purpose.?
Q.7. What is List Operator and what is the Purpose.?
Q.8. What are String Operators- wildcard, and what are the
types and Purpose.?
Q.9. What is UNKNOWN value.? How this Value can be
Retrieved.?
Q.10. What is the Purpose of ISNULL.?
Review
Thank You.