Mashandisiro ekushandisa iyo SQL Drop, Truncate uye Delete Statement

Iyo SQL DELETE chirevo chinoshandiswa kudzima zvinyorwa kubva patafura nepo DROP chirevo chinoshandiswa kudzima tafura kana dhatabhesi.

I TRUNCATE TABLE chirevo chinogona kushandiswa kudzima zvinyorwa kubva patafura.

Kubvisa Zvinyorwa Kubva Patafura

I DELETE chirevo muSQL chinoshandiswa kudzima zvinyorwa kubva patafura ye database. Tinogona kubvisa zvese zvinyorwa kubva patafura kana kudzima chaiwo marekodhi tichishandisa WHERE chirevo.

DELETE FROM table_name WHERE condition;

SQL DELETE Chirevo Mienzaniso

Ngatifungei kuti tine tafura inonzi 'Vashandi' ine zvinyorwa zvinotevera:

+------------+-----------+----------+------------+ | EmployeeID | FirstName | LastName | Department | +------------+-----------+----------+------------+ | 1

| Mark
| Otto
| Finance | | 2

| Jacob
| Thornton | IT
| | 3

| Su
| Bird
| Marketing | | 4

| Sam
| Burger | IT
| +------------+-----------+----------+------------+

Delete Imwe Rekodhi

Iyi inotevera kodhi inobvisa 'Jacob Thornton' kubva kune 'Vashandi' tafura:

DELETE FROM Employees WHERE FirstName = 'Jacob' AND LastName = 'Thornton'; Ongorora:Mumuenzaniso wepamusoro, tinoshandisa mamiriro maviri, KUPI uye Uye , kureva zita rekutanga uye zita rokupedzisa. Izvi ndezvekuona kuti tinodzima rekodhi chaiyo, kana paine mumwe mushandi ane zita rekutanga.

Delete Zvese Zvinyorwa Kubva paTafura

Iyi inotevera kodhi inobvisa zvese zvinyorwa kubva patafura ye 'Vashandi':



DELETE * FROM Employees; Ongorora:Iyo Bvisa chirevo chinobvisa zvinyorwa kubva patafura, asi hachibvise tafura pachayo.

SQL TRUNCATE TABLE Chirevo

I TRUNCATE TABLE chirevo chinogona zvakare kushandiswa kudzima zvinyorwa kubva patafura, asi kwete iyo tafura pachinzvimbo.

Muenzaniso:

TRUNCATE TABLE table_name;

SQL Kudonhedza Chirevo

I DROP chirevo muSQL chinoshandiswa kudzima tafura kana dhatabhesi.

Maitiro Ekudonhedza Tafura muSQL

Iyi inotevera kodhi inodonhedza tafura inonzi 'Vashandi':

DROP TABLE 'Employees'; Ongorora:Tora hanya zvakanyanya paunenge uchishandisa iyo DONHEDZA chirevo. Kana uchidonhedza tafura, ichabvisa zvese zvinyorwa mukati petafura zvakare.

Maitiro Ekudonhedza Dhatabhesi muSQL

Iyi inotevera kodhi inodonhedza dhatabhesi inonzi 'VashandiDB':

DROP DATABASE 'EmployeesDB'; Ongorora:Tora hanya zvakanyanya paunenge uchishandisa iyo DONHEDZA chirevo. Kana uchidonhedza dhatabhesi, ichabvisa matafura ese mukati me database.