UPDATE

UPDATE bayonoti jadvaldagi mavjud yozuvlarni o'zgartirish uchun ishlatiladi.

SU

SQL UPDATE Bayonoti Nima?

UPDATE bayonoti jadvaldagi mavjud yozuvlarni o'zgartirish uchun ishlatiladi.

UPDATE Sintaksisi

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Eslatma: Jadvaldagi yozuvlarni yangilashda ehtiyot bo'ling! UPDATE bayonotidagi WHERE klauzasi qaysi yozuv(lar)ni yangilanishini belgilaydi. Agar WHERE klauzasini e'tiborsiz qoldirsangiz, jadvaldagi barcha yozuvlar yangilanadi!

Demo Ma'lumotlar Bazasi

Quyida misollarda ishlatiladigan Customers jadvalidan tanlov keltirilgan:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

UPDATE Jadvali

Quyidagi SQL bayonoti birinchi mijozni (CustomerID = 1) yangi aloqa shaxsi va yangi shahar bilan yangilaydi:

Misol O'zingizning SQL serveringizni oling

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

"Customers" jadvalidan olingan tanlov endi quyidagi ko'rinishda bo'ladi:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteAlfred SchmidtObere Str. 57Frankfurt12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

Bir Nechta Yozuvni Yangilash

WHERE klauzasi qanchalik ko'p yozuv yangilanadiganligini belgilaydi.

Quyidagi SQL bayonoti "Country" qiymati "Mexico" bo'lgan barcha yozuvlarda ContactName ni "Juan" ga yangilaydi:

Misol

UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';

"Customers" jadvalidan olingan tanlov endi quyidagi ko'rinishda bo'ladi:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteAlfred SchmidtObere Str. 57Frankfurt12209Germany
2Ana Trujillo Emparedados y heladosJuanAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaJuanMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

Yangilash Ogohlantirishi!

Yozuvlarni yangilashda ehtiyot bo'ling. Agar WHERE klauzasini e'tiborsiz qoldirsangiz, barcha yozuvlar yangilanadi!

Misol

UPDATE Customers
SET ContactName='Juan';

"Customers" jadvalidan olingan tanlov endi quyidagi ko'rinishda bo'ladi:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteJuanObere Str. 57Frankfurt12209Germany
2Ana Trujillo Emparedados y heladosJuanAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaJuanMataderos 2312México D.F.05023Mexico
4Around the HornJuan120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpJuanBerguvsvägen 8LuleåS-958 22Sweden

Ushbu sahifada

Xato haqida xabar berish