-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_Delete.sql
More file actions
72 lines (49 loc) · 1.99 KB
/
06_Delete.sql
File metadata and controls
72 lines (49 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ============================== DELETE ===================================
DELETE FROM table_name;
→ Deletes all records in the table.
DELETE FROM table_name WHERE column_name = value;
→ Deletes specific records using filtering.
=========================================================================*/
CREATE TABLE ogrenciler
(
id CHAR(3),
isim VARCHAR(50),
veli_isim VARCHAR(50),
yazili_notu INT
);
INSERT INTO ogrenciler VALUES(101, 'Haluk Bilgin', 'JavaCan',75);
INSERT INTO ogrenciler VALUES(102, 'Ipek Bilir', 'JavaNaz',85);
INSERT INTO ogrenciler VALUES(103, 'Harun Bil', 'JavaSu',85);
INSERT INTO ogrenciler VALUES(104, 'Hasan Bilmiş', 'JavaTar',95);
INSERT INTO ogrenciler VALUES(105, 'Halime Bilse', 'JavvaNur',83);
INSERT INTO ogrenciler VALUES(106, 'Haline Bak', 'JavaLar',99);
INSERT INTO ogrenciler VALUES(107, 'Hanimiş Bee', 'JavaHan',91);
SELECT * FROM ogrenciler;
/*
DELETE FROM ogrenciler;
→ Deletes all data in the table.
ROLLBACK can restore deleted data if transaction control is supported.
*/
/* =============================================================================
Deleting records using filtering (WHERE clause)
=============================================================================== */
-- Task01 -> Delete student with id = 102
DELETE FROM ogrenciler WHERE id = 102;
-- Task02 -> Delete record where name is Haluk Bilgin
DELETE FROM ogrenciler WHERE isim = 'Haluk Bilgin';
-- Task03 -> Delete records where name is Halime Bilse or Hasan Bilmis
DELETE FROM ogrenciler
WHERE isim = 'Halime Bilse'
OR isim = 'Hasan Bilmis';
-- Task04 -> Delete record where name is Harun Bil and id is 105
DELETE FROM ogrenciler
WHERE isim = 'Harun Bil'
AND id = 105;
-- Task05 -> Delete records where id is greater than 103
DELETE FROM ogrenciler
WHERE id > 103;
-- Task06 -> Delete records where id is 106, 107, or 104
DELETE FROM ogrenciler
WHERE id IN (106, 107, 104);
-- Task07 -> Delete all records in the table
DELETE FROM ogrenciler;