Uyihlaziya njani idatha ye-SQL ekhoyo

Ngu-Allen G. Taylor

Ngenxa yokuba umhlaba uhlala utshintsha, i-SQL yolwazi esetyenziselwa ukumodareyitha imiba yehlabathi nayo kufuneka itshintshe. Umthengi unokutshintsha idilesi yakhe. Ubungakanani bemveliso esitokisini inokutshintsha. Amanani obalo omdlali webhola yomnyazi atshintsha qho xa edlala komnye umdlalo. Ukuba i-database yakho inezinto ezinjalo, kuya kufuneka uzihlaziye rhoqo.



I-SQL ibonelela nge-UHLAZIYOingxelo yokutshintsha idatha kwitafile. Ngokusebenzisa ifayili enyeUHLAZIYOingxelo, ungatshintsha enye, enye, okanye yonke imiqolo etafileni. Inkqubo ye-UHLAZIYOIsiteyitimenti sisebenzisa esi syntax silandelayo:



UPDATE table_name SET column_1 = expression_1, column_2 = expression_2, ..., column_n = expression_n [WHERE predicates] ;

Inkqubo ye-KUPHIIgatya liyazikhethela. Eli gatya licacisa imiqolo oyihlaziyayo. Ukuba awusebenzisi i-KUPHIIgatya, yonke imigca etafileni iyahlaziywa. Inkqubo ye-SETIgatya licacisa amaxabiso amatsha kwiikholamu ozitshintshayo.

Cinga ngale tafile yeCustomer.



Igama Isixeko Ikhowudi yengingqi Umnxeba
UAbe Abelson Indawo yaseSpanish (714) Ngama-555-1111
UBill Bailey I-Decatur (714) Ngama-555-2222
UChuck Wood UPhilo (714) Ngama-555-3333
UDon Stetson UPhilo (714) Ngama-555-4444
UDolph Stetson UPhilo (714) Ngama-555-5555

Uluhlu lwabathengi luyatshintsha ngamanye amaxesha - njengoko abantu behamba, batshintsha iinombolo zefowuni, njalo njalo. Masithi u-Abe Abelson usuka e-Springfield esiya eKankakee. Ungayihlaziya ingxelo yakhe etafileni ngokusebenzisa oku kulandelayoUHLAZIYOingxelo:

UPDATE CUSTOMER SET City = 'Kankakee', Telephone = '666-6666' WHERE Name = 'Abe Abelson' ;

Le ngxelo ibangela utshintsho oluboniswe kwiTheyibhile 6-2.

Igama Isixeko Ikhowudi yengingqi Umnxeba
UAbe Abelson Kankakee (714) Ngowama-666-6666
UBill Bailey I-Decatur (714) Ngama-555-2222
UChuck Wood UPhilo (714) Ngama-555-3333
UDon Stetson UPhilo (714) Ngama-555-4444
UDolph Stetson UPhilo (714) Ngama-555-5555

Ungasebenzisa ingxelo efanayo ukuvuselela imiqolo emininzi. Thatha ukuba uPhilo ufumana ukwanda kwenani labantu kwaye ngoku ufuna ikhowudi yendawo yakhe. Ungayitshintsha yonke imiqolo yabathengi abahlala ePhilo ngokusebenzisa enyeUHLAZIYOingxelo, ngolu hlobo lulandelayo:



UPDATE CUSTOMER SET AreaCode = '(619)' WHERE City = 'Philo' ;

Itafile ngoku ijongeka njengaleyo iboniswe kwiTheyibhile 6-3.

Igama Isixeko Ikhowudi yengingqi Umnxeba
UAbe Abelson Kankakee (714) Ngowama-666-6666
UBill Bailey I-Decatur (714) Ngama-555-2222
UChuck Wood UPhilo (619) Ngama-555-3333
UDon Stetson UPhilo (619) Ngama-555-4444
UDolph Stetson UPhilo (619) Ngama-555-5555

Ukuhlaziya yonke imiqolo yetafile kulula kunokuhlaziya kuphela eminye yemigca. Awudingi ukusebenzisa ifayile ye-KUPHIIgatya lokuthintela ingxelo. Khawufane ucinge ukuba isixeko saseRantoul siye safumana amandla amakhulu kwezopolitiko kwaye ngoku asihlanganisi nje iKankakee, iDecatur, nePhilo, kodwa nazo zonke izixeko needolophu ezikulwazi olugciniweyo. Ungayihlaziya yonke imiqolo usebenzisa ingxelo enye:

UPDATE CUSTOMER SET City = 'Rantoul' ;

Itheyibhile 6-4 ibonisa iziphumo.

Igama Isixeko Ikhowudi yengingqi Umnxeba
UAbe Abelson Rantoul (714) Ngowama-666-6666
UBill Bailey Rantoul (714) Ngama-555-2222
UChuck Wood Rantoul (619) Ngama-555-3333
UDon Stetson Rantoul (619) Ngama-555-4444
UDolph Stetson Rantoul (619) Ngama-555-5555

Xa usebenzisaKUPHIIgatya kunyeUHLAZIYOingxelo yokuthintela ukuba yeyiphi na imiqolo ehlaziyiweyo, imixholo yeKUPHIIgatya linokuba yi- khetha -ukuyaKHETHAingxelo, isiphumo sayo sisetyenziswa njengegalelo ngomnye umntuKHETHAingxelo.

Masithi ungumthengisi wevenkile egciniweyo kwaye ugcino lwedatha yakho ibandakanya itafile YABathengisi enamagama abo bonke abavelisi othenga kubo iimveliso. Unetafile ye-PRODUCT enamagama wazo zonke iimveliso ozithengisayo kunye namaxabiso owabiza wona. Itafile ye-VENDOR ineekholamuUmthengisiID,UmthengisiIgama,Isitalato,Isixeko,Urhulumente, kunyeZip. Itheyibhile ye PRODUCT inayoImvelisoID,Igama lemveliso,UmthengisiID, kunyeIntengiso.

Umthengisi wakho, iCumulonimbus Corporation, ithathe isigqibo sokunyusa amaxabiso azo zonke iimveliso zayo ngepesenti ye-10. Ukugcina umda wenzuzo yakho, kuya kufuneka unyuse amaxabiso akho kwiimveliso ozifumanayo eCumulonimbus ngepesenti ye-10. Unokwenza njalo ngokusebenzisa oku kulandelayoUHLAZIYOingxelo:

UPDATE PRODUCT SET SalePrice = (SalePrice * 1.1) WHERE VendorID IN (SELECT VendorID FROM VENDOR WHERE VendorName = 'Cumulonimbus Corporation') ;

I-subselect ifumana ifayile ye-UmthengisiIDEhambelana neCumulonimbus. Ungasebenzisa iUmthengisiIDifildi kwitafile ye-PRODUCT ukufumana imiqolo ofuna ukuyivuselela. Amaxabiso kuzo zonke iimveliso zeCumulonimbus anyuka nge-10 yepesenti; amaxabiso kuzo zonke ezinye iimveliso ahlala efanayo.