Sql server® 2012 t-sql fundamentals



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

 

CHAPTER 3

 

Joins


 

 107

Each audit row stores a log serial number (lsn), the key of the modified row (orderidproductid), the 

name of the modified column (columnname), the old value (oldval), the new value (newval), when the 

change took place (dt), and who made the change (loginname). The table has a foreign key defined on 

the attributes orderidproductid, referencing the primary key of the OrderDetails table, which is defined 

on the attributes orderidproductid. Assume that you already have in place in the OrderDetailsAudit 

table a process that logs, or audits, all changes taking place in column values in the OrderDetails table. 

You need to write a query against the OrderDetails and OrderDetailsAudit tables that returns 

information about all value changes that took place in the column qty. In each result row, you need 

to return the current value from the OrderDetails table and the values before and after the change 

from the OrderDetailsAudit table. You need to join the two tables based on a primary key–foreign key 

relationship, like this.

SELECT OD.orderid, OD.productid, OD.qty, 

  ODA.dt, ODA.loginname, ODA.oldval, ODA.newval 

FROM Sales.OrderDetails AS OD 

  JOIN Sales.OrderDetailsAudit AS ODA 

    ON OD.orderid = ODA.orderid 

    AND OD.productid = ODA.productid 

WHERE ODA.columnname = N'qty';

Because the relationship is based on multiple attributes, the join condition is composite.




Download 10,93 Mb.

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