SQL yog lus nug uas nquag siv los ua cov haujlwm hauv DBMS tshwj xeeb. Muaj cov kws tshaj lij rau SQL, koj tuaj yeem sau ntau yam web applications siv MySQL lossis Oracle database. Siv cov lus nug, txhua cov ntxhuav hauv lub database tau tsim, thiab qee cov ntaub ntawv raug khaws cia, hloov thiab rov qab los.
Cov Lus Qhia
Kauj ruam 1
SQL cov lus txib tuaj yeem muab faib ua ntau pawg:
- DDL, uas yog siv los hloov thiab rho tawm cov khoom hauv cov ntaub ntawv;
- DCL, uas tswj kev nkag mus rau lub chaw khaws ntaub ntawv;
- TCL, uas txiav txim siab qhov tshwm sim ntawm kev ua haujlwm;
- DML, uas yog lub luag haujlwm rau hloov cov ntaub ntawv.
Kauj ruam 2
Qhov tseem ceeb tshaj plaws rau kev tsim cov lus nug yog SQL Tsim Rooj. Nws qhia txog cov qauv ntawm lub rooj tsim tawm. Ua ib feem ntawm cov lus nug no, koj tuaj yeem txhais cov kem hauv zos uas txhais tau hom thiab npe ntawm cov ntaub ntawv hauv kab ntawv muab. Piv txwv li:
TSIB LUB ROOJ xub thawj (id rau menyuam,
lub npe varchar (255), Surname varchar (255) Lub xeem);
Cov lus nug yuav tsim Firsttable nrog slots id, lub npe, thiab lub xeem, uas tuaj yeem muab teeb rau qhov tsim nyog.
Kauj ruam 3
Lwm cov lus txib tseem ceeb yog INSERT, uas nkag mus rau cov ntaub ntawv tshwj xeeb rau hauv qhov chaw tsim twb tau tsim, thiab muaj cov ntawv cim:
INSERT INTO `table` (` column1 `,` column2 `) QHOV TSEEB (“val1”,“val2”)
Qhov twg column1, column2 yog cov lej koj tsim, thiab val1 thiab val2 yog qhov tseem ceeb uas koj xav tau ntxig.
Kauj ruam 4
Txhawm rau khaws cov ntaub ntawv rau cov zis lossis lwm cov haujlwm, cov lus nug SELECT siv, uas zoo li:
XAIV * LOS NTAWM `cov lus`
Tsis tas li ntawd, koj tuaj yeem tsim cov kev ntsuas rau cov ntaub ntawv los ntawm kab ntawv nyias. Piv txwv li, yog tias peb xav kom khaws lub npe los ntawm Firsttable, tom qab ntawd cov lus nug yuav zoo li no:
XAIV * LOS NTAWM `Xub thawj` qhov twg lub npe = '$ npe'
Kauj ruam 5
Koj tuaj yeem sau cov lus nug hauv.txt lossis.sql cov ntaub ntawv uas siv cov Notepad ib txwm muaj. Sau koj cov lus txib, tom qab ntawd koj tuaj yeem thauj lawv, piv txwv li, los ntawm phpMyAdmin interface hauv cov tswj hwm ntawm koj lub hosting lossis DBMS.