Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet149/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   145   146   147   148   149   150   151   152   ...   443
Bog'liq
BookSQL

  

99

C H A P T E R   3

Joins

T

he FROM clause of a query is the first clause to be logically processed, and within the FROM 



clause, table operators operate on input tables. Microsoft SQL Server supports four table opera-

tors—JOINAPPLYPIVOT, and UNPIVOT. The JOIN table operator is standard, whereas APPLYPIVOT

and UNPIVOT are T-SQL extensions to the standard. Each table operator acts on tables provided to 

it as input, applies a set of logical query processing phases, and returns a table result. This chapter 

focuses on the JOIN table operator. The APPLY operator will be covered in Chapter 5, “Table Expres-

sions,” and the PIVOT and UNPIVOT operators will be covered in Chapter 7, “Beyond the Fundamen-

tals of Querying.”

JOIN table operator operates on two input tables. The three fundamental types of joins are 

cross joins, inner joins, and outer joins. These three types of joins differ in how they apply their logical 

query processing phases; each type applies a different set of phases. A cross join applies only one 

phase—Cartesian Product. An inner join applies two phases—Cartesian Product and Filter. An outer 

join applies three phases—Cartesian Product, Filter, and Add Outer Rows. This chapter explains each 

of the join types and the phases involved in detail.

Logical query processing describes a generic series of logical steps that for any specified query pro-

duces the correct result, whereas physical query processing is the way the query is processed by the 

RDBMS engine in practice. Some phases of logical query processing of joins might sound inefficient, 

but the inefficient phases will be optimized by the physical implementation. It’s important to stress 

the term logical in logical query processing. The steps in the process apply operations to the input 

tables based on relational algebra. The database engine does not have to follow logical query pro-

cessing phases literally, as long as it can guarantee that the result that it produces is the same as that 

dictated by logical query processing. The SQL Server relational engine often applies many shortcuts 

for optimization purposes when it knows that it can still produce the correct result. Even though this 

book’s focus is on understanding the logical aspects of querying, I want to stress this point to avoid 

any misunderstanding and confusion.

Cross Joins

Logically, a cross join is the simplest type of join. A cross join implements only one logical query proc-

essing phase—a Cartesian Product. This phase operates on the two tables provided as inputs to the 

join and produces a Cartesian product of the two. That is, each row from one input is matched with all 

rows from the other. So if you have m rows in one table and n rows in the other, you get m×n rows in 

the result.

www.it-ebooks.info



100  

Microsoft SQL Server 2012 T-SQL Fundamentals

SQL Server supports two standard syntaxes for cross joins—the ANSI SQL-92 and ANSI SQL-89 syn-

taxes. I recommend that you use the ANSI-SQL 92 syntax for reasons that I’ll describe shortly. There-

fore, ANSI-SQL 92 syntax is the main syntax that I use throughout the book. For the sake of complete-

ness, I describe both syntaxes in this section.




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   145   146   147   148   149   150   151   152   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish