Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet160/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   156   157   158   159   160   161   162   163   ...   443
Bog'liq
BookSQL

More Join Examples

This section covers a few join examples that are known by specific names: composite joins, non-equi 

joins, and multi-join queries.

Composite Joins

composite join is simply a join based on a predicate that involves more than one attribute from 

each side. A composite join is commonly required when you need to join two tables based on a 

primary key–foreign key relationship and the relationship is composite; that is, based on more than 

one attribute. For example, suppose you have a foreign key defined on dbo.Table2, columns col1col2

referencing dbo.Table1, columns col1col2, and you need to write a query that joins the two based on 

a primary key–foreign key relationship. The FROM clause of the query would look like this.

FROM dbo.Table1 AS T1 

  JOIN dbo.Table2 AS T2 

    ON T1.col1 = T2.col1 

    AND T1.col2 = T2.col2

For a more tangible example, suppose that you need to audit updates to column values 

against the OrderDetails table in the TSQL2012 database. You create a custom auditing table 

called OrderDetailsAudit.

USE TSQL2012; 

IF OBJECT_ID('Sales.OrderDetailsAudit', 'U') IS NOT NULL 

  DROP TABLE Sales.OrderDetailsAudit; 

CREATE TABLE Sales.OrderDetailsAudit 

  lsn        INT NOT NULL IDENTITY, 



  orderid    INT NOT NULL, 

  productid  INT NOT NULL, 

  dt         DATETIME NOT NULL, 

  loginname  sysname NOT NULL, 

  columnname sysname NOT NULL, 

  oldval     SQL_VARIANT, 

  newval     SQL_VARIANT, 

  CONSTRAINT PK_OrderDetailsAudit PRIMARY KEY(lsn), 

  CONSTRAINT FK_OrderDetailsAudit_OrderDetails 

    FOREIGN KEY(orderid, productid) 

    REFERENCES Sales.OrderDetails(orderid, productid) 

);

www.it-ebooks.info





Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   156   157   158   159   160   161   162   163   ...   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