Eslatma
SQL Server 2014 va undan oldingi versiyalar uchun Transact-SQL sintaksisi tavsifiga havolalar uchun oldingi versiyalar uchun hujjatlarga qarang .
55-Mavzu: Ma’lumotni o‘zgartirish
Reja:
1. Mavjud ma'lumotlarni o'zgartirish
2. UPDATE
3. So'rov natijasi
Mavjud ma'lumotlarni o'zgartirish uchun biz SQL UPDATE so'rovidan foydalanamiz .
Qaysi ma'lumotlarni o'zgartirish kerakligini aniq belgilash uchun biz WHERE shartli bandidan foydalanishimiz kerak .
Ushbu so'rov quyidagicha ko'rinadi:
UPDATE имя_таблицы
SET колонка1 = значение1, колонка2 = значение2, колонкаN = значениеN
WHERE [условие1];
Shartlarni yaxshilash uchun VA/OR operatorlaridan ham foydalanishimiz mumkin.
Misol:
Aytaylik, bizda quyidagi ma'lumotlarni o'z ichiga olgan ishlab chiquvchilar jadvali bor:
+----+-------------------+------------+------------+--------+
| ID | NAME | SPECIALTY | EXPERIENCE | SALARY |
+----+-------------------+------------+------------+--------+
| 1 | Eugene Suleimanov | Java | 2 | 2000 |
| 2 | Peter Romanenko | Java | 3 | 3500 |
| 3 | Andrei Komarov | JavaScript | 2 | 2100 |
| 4 | Konstantin Geiko | C# | 2 | 2000 |
| 5 | Asya Suleimanova | UI/UX | 2 | 1800 |
+----+-------------------+------------+------------+--------+
Aytaylik, Yevgeniy Sulaymonov ismli dasturchining maoshini o‘zgartirishimiz kerak. Buning uchun biz quyidagi buyruqni ishlatishimiz kerak:
mysql> UPDATE developers
SET SALARY = 2500
WHERE NAME LIKE 'Eugene Suleimanov';
Natijada, bizning yozuvimiz o'zgaradi va bizning jadvalimiz allaqachon quyidagi ma'lumotlarni o'z ichiga oladi:
+----+-------------------+------------+------------+--------+
| ID | NAME | SPECIALTY | EXPERIENCE | SALARY |
+----+-------------------+------------+------------+--------+
| 1 | Eugene Suleimanov | Java | 2 | 2500 |
| 2 | Peter Romanenko | Java | 3 | 3500 |
| 3 | Andrei Komarov | JavaScript | 2 | 2100 |
| 4 | Konstantin Geiko | C# | 2 | 2000 |
| 5 | Asya Suleimanova | UI/UX | 2 | 1800 |
+----+-------------------+------------+------------+--------+
Agar biz bir nechta sohalarni, masalan, tajriba va ish haqini o'zgartirmoqchi bo'lsak, so'rovimiz quyidagicha ko'rinadi:
mysql> UPDATE developers
SET EXPERIENCE = 3, SALARY = 2500
WHERE NAME LIKE 'Andrei Komarov';
Ushbu so'rov natijasida bizning ishlab chiquvchilar jadvali quyidagicha ko'rinadi:
+----+-------------------+------------+------------+--------+
| ID | NAME | SPECIALTY | EXPERIENCE | SALARY |
+----+-------------------+------------+------------+--------+
| 1 | Eugene Suleimanov | Java | 2 | 2500 |
| 2 | Peter Romanenko | Java | 3 | 3500 |
| 3 | Andrei Komarov | JavaScript | 3 | 2500 |
| 4 | Konstantin Geiko | C# | 2 | 2000 |
| 5 | Asya Suleimanova | UI/UX | 2 | 1800 |
+----+-------------------+------------+------------+--------+
Bu mavjud ma'lumotlarni o'zgartirish usullarini o'rganishimizni yakunlaydi.
Keyingi maqolada biz yozuvlarni o'chirish jarayonini ko'rib chiqamiz.
Do'stlaringiz bilan baham: |