Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet319/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   315   316   317   318   319   320   321   322   ...   443
Bog'liq
BookSQL

 

CHAPTER 8

 

Data Modification



 

 279

TOP option based on a logical ORDER BY clause that defines precedence among rows. You can then 

issue the modification statement against the table expression.

For example, the following code deletes the 50 orders with the lowest order ID values rather than 

just any 50 rows.

WITH C AS 

  SELECT TOP(50) * 



  FROM dbo.Orders 

  ORDER BY orderid 

DELETE FROM C;



Similarly, the following code updates the 50 orders with the highest order ID values, increasing 

their freight values by 10.

WITH C AS 

  SELECT TOP(50) * 



  FROM dbo.Orders 

  ORDER BY orderid DESC 

UPDATE C 



  SET freight += 10.00;

In SQL Server 2012, you can use the OFFSET-FETCH option instead of TOP in the inner SELECT 

queries. Here’s the revised DELETE example.

WITH C AS 

  SELECT * 



  FROM dbo.Orders 

  ORDER BY orderid 

  OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

DELETE FROM C;



And here’s the revised UPDATE example.

WITH C AS 

  SELECT * 



  FROM dbo.Orders 

  ORDER BY orderid DESC 

  OFFSET 0 ROWS FETCH FIRST 50 ROWS ONLY 

UPDATE C 



  SET freight += 10.00;

www.it-ebooks.info




280  

Microsoft SQL Server 2012 T-SQL Fundamentals




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   315   316   317   318   319   320   321   322   ...   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