Key Difference – DDL vs DML
A database yog siv los khaws cov ntaub ntawv. Muaj ntau hom databases. Ib hom databases yog Relational Databases. Hauv cov ntaub ntawv no, cov ntaub ntawv khaws cia hauv cov ntxhuav. Cov ntxhuav muaj cov kab thiab kab. Ib kab yog cov ntaub ntawv, thiab ib kem yog ib daim teb. Cov rooj sib txuas nrog kev txwv xws li cov yuam sij tseem ceeb thiab cov yuam sij txawv teb chaws. Relational Database Management Systems yog siv los khaws, khaws thiab tswj cov ntaub ntawv. Ib txhia ntawm lawv yog MSSQL, Oracle, MySQL. Cov lus uas siv los ua haujlwm ntawm kev sib raug zoo databases hu ua Structured Query Language (SQL). Cov Ntaub Ntawv Txhais Lus (DDL) thiab Cov Ntaub Ntawv Tswj Cov Lus (DML) yog cov pawg ntawm SQL. Qhov sib txawv tseem ceeb ntawm DDL thiab DML yog DDL siv los hloov cov qauv ntawm cov ntaub ntawv thaum DML siv los tswj cov ntaub ntawv hauv database.
DDL yog dab tsi?
DDL sawv cev rau Cov Lus Txhais Lus. Cov lus no yog siv los hloov cov qauv ntawm cov ntaub ntawv. Tsim, Hloov, Tso, Txiav yog qee cov lus txib DDL.
Daim duab 01: SQL
Examples of DDL Commands
Saib cov piv txwv hauv qab no DDL sau hauv TSQL (MSSQL server);
nqe lus hauv qab no yuav tsim cov ntaub ntawv npe hu ua "tus neeg ua haujlwm".
tsim cov neeg ua haujlwm database;
nqe lus hauv qab no yuav tshem tawm tus neeg ua haujlwm database uas twb muaj lawm.
poob database neeg ua haujlwm;
Qee DDL nqe lus yog siv los tsim lub rooj.
create rooj tbl_employee
(id int tsis null, firstName varchar(30), department varchar(30), primary key(id));
Kev hloov pauv tuaj yeem siv los ntxiv cov kab, hloov cov kab uas twb muaj lawm thiab tso cov kab.
Ib qho piv txwv ntxiv cov nyiaj them rau kab tshiab rau lub rooj tbl_employee yog raws li hauv qab no.
hloov rooj tbl_employee ntxiv cov nyiaj them tus lej (4, 2);
nqe lus hauv qab no tuaj yeem siv los tso lub rooj.
poob rooj tbl_employee;
Nws tseem tuaj yeem khaws cov qauv rooj thiab tshem tawm cov ntsiab lus hauv lub rooj. Qhov no tuaj yeem ua tiav siv cov lus txib truncate. Nws tuaj yeem rho tawm tag nrho cov ntaub ntawv hauv lub rooj thiab nws tseem yuav tshem tawm cov ntaub ntawv hauv lub cim xeeb. Yog li, nws tsis tuaj yeem thim rov qab ua haujlwm.
truncate rooj tbl_employee;
DML yog dab tsi?
DML stands for Data Manipulation Language. DML yog siv los tswj cov ntaub ntawv hauv database. Cov lus txib DML feem ntau yog: ntxig, tshem tawm, hloov tshiab.
Examples of DML Commands
Ua raws li yog qee qhov piv txwv DML sau siv TSQL (MSSQL server)
nqe lus hauv qab no yog siv los ntxig qhov tseem ceeb rau hauv lub rooj tbl_employee.
Insert into tbl_employee (id, firstName, department) values (1, “Ann”, “Human Resources”);
nqe lus hauv qab no yog siv los rho tawm cov ntaub ntawv. Rho tawm hais kom ua yuav rho tawm cov ntaub ntawv nyob rau hauv lub rooj tab sis nws tsis tag rho tawm ntawm lub cim xeeb. Yog li ntawd, nws tuaj yeem rov qab ua haujlwm.
delete from tbl_employee where id=1;
Cov lus qhia hloov tshiab tau muab hauv qab no yog siv los hloov kho ib kab tshwj xeeb.
update tbl_employee set department='Accounting' where id=1;
DDL thiab DML yog dab tsi?
Ob leeg yog hom lus nug lus (SQL)
Qhov txawv ntawm DDL thiab DML yog dab tsi?
DDL vs DML |
|
DDL yog hom SQL uas siv los hloov cov qauv ntawm cov ntaub ntawv. | DML yog hom SQL uas siv los tswj cov ntaub ntawv hauv database. |
DDL nqe lus tsis tuaj yeem thim rov qab. | DML nqe lus tuaj yeem thim rov qab. |
Tsim, hloov, poob, txiav thiab lwm yam. poob rau hauv DDL. | Insert, hloov tshiab, rho tawm thiab lwm yam. poob rau hauv DML. |
Kev Ua Haujlwm | |
DDL nqe lus cuam tshuam rau tag nrho lub rooj. | DML cuam tshuam ib lossis ntau kab. |
Summary -DDL vs DML
Relational Database yog hom database ntau. Structured Query Language (SQL) yog siv los ua haujlwm xws li khaws cia, tswj xyuas thiab khaws cov ntaub ntawv los ntawm cov ntaub ntawv sib txheeb. SQL muaj peb yam subcategories. Lawv yog DDL, DML thiab DCL. Qhov txawv ntawm DDL thiab DML yog DDL siv los hloov cov qauv ntawm cov ntaub ntawv thiab DML yog siv los tswj cov ntaub ntawv hauv database.
Download the PDF Version of DDL vs DML
Koj tuaj yeem rub tawm PDF version ntawm kab lus no thiab siv nws rau offline hom phiaj raws li daim ntawv ceeb toom. Thov download PDF version ntawm no Qhov txawv Ntawm DDL thiab DML