1. Mavzu. T-SQL asoslari. DML (Update, Delete).
Buxoro davlat universiteti
Amaliy matematika va dasturlash texnologiyalari
Kafedrasi o`qituvchisi: Xayatov Xurshidjon Usmanovich
Reja:
1.
Ma'lumotlarni yangilash. UPDATE operatori.
2.
Ma'lumotlar o'chirish. DELETE operatori.
Ma'lumotlarni yangilash. UPDATE operatori.
UPDATE buyrug'i jadvaldagi mavjud satrlarni yangilash uchun ishlatiladi.
U quyidagi sintaksisga ega:
UPDATE JadvalNomi
SET
UstunNomi1 = Qiymat1,
UstunNomi2 = Qiymat2,
...
UstunNomiN = QiymatN
[FROM
Jadval2 yoki TanlovSo`rovi
AS
Taxallus_Berish
]
[WHERE
Tanlov_Sharti
]
Ma'lumotlarni yangilash. UPDATE
operatori.
Masalan, barcha mahsulotlar narxini 5000
ga oshiramiz:
UPDATE Products
SET Price = Price + 5000
SELECT * FROM Products
SELECT * FROM Products
Ma'lumotlarni yangilash. UPDATE
operatori.
Shartdan foydalanib va ishlab chiqaruvchi
"Samsung " nomini "Samsung Inc. "
nomiga o'zgartiring:
UPDATE Products
SET Manufacturer = 'Samsung Inc.'
WHERE Manufacturer = 'Samsung'
SELECT * FROM Products
SELECT * FROM Products
Ma'lumotlarni yangilash. UPDATE
operatori.
Murakkab so'rov - Ishlab chiqaruvchi maydonini "Apple"
qiymatidan "Apple Inc." qiymatiga almashtiring.
birinchi 2 ta satrini:
UPDATE Products
SET Manufacturer = 'Apple Inc.'
FROM
(
SELECT TOP 2 FROM Products WHERE Manufacturer='Apple'
) AS Selected
WHERE Products.Id = Selected.Id
SELECT * FROM Products
SELECT * FROM Products
Ma'lumotlar o'chirish. DELETE operatori.
O'chirish uchun DELETE buyrug'idan foydalanamiz:
DELETE [FROM] Jadval_Nomi
WHERE O`chirish_Sharti
Masalan, id ustunining qiymati 9 bo'lgan satrlarni
o'chiramiz:
DELETE Products
WHERE Id=9
Ma'lumotlar o'chirish. DELETE operatori.
Yoki Xiaomi tomonidan ishlab chiqarilgan va narxi 15000 dan past bo'lgan
barcha mahsulotlarni o'chiramiz:
DELETE Products
WHERE Manufacturer='Xiaomi' AND Price < 15000
Ma'lumotlar o'chirish. DELETE operatori.
SELECT * FROM Products
SELECT * FROM Products
DELETE Products FROM
(SELECT TOP 2 * FROM Products
WHERE Manufacturer='Apple') AS Selected
WHERE Products.Id = Selected.Id
murakkab so’rov - ishlab chiqaruvchisi Apple
bo'lgan birinchi ikkita mahsulotni o`chiramiz:
Nazorat savollari
1. So`rovda filtrlarni qo`llashdan maqsad nima?
2. Ko’rsatilgan jadvalning ko`rsatilgan ustunlari qiymatini yangilang?
3. Berilgan talab asosida jadvalni ustunini yangilang ?
4. UPDATE operatorining vazifasi va unda bitta misol keltiring?
5. DELETE operatorining vazifasi va unda bitta misol keltiring?
6. Ko’rsatilgan jadvalning barcha yozuvlarini o`chiring?
7. Ko`rsatilgan jadvalni talab qilingan yozuvlarini o`chiring
?
Dostları ilə paylaş: |