-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_On Delete-Cascade.sql
More file actions
41 lines (32 loc) · 1.31 KB
/
05_On Delete-Cascade.sql
File metadata and controls
41 lines (32 loc) · 1.31 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
/*============================== ON DELETE CASCADE =============================
When deleting a parent record, instead of deleting child records first,
the **ON DELETE CASCADE** option allows automatic deletion of related child records.
This means:
Deleting a parent record will automatically delete dependent child records.
To use cascade deletion, add **ON DELETE CASCADE** at the end of the foreign key definition.
==============================================================================*/
CREATE TABLE ogrenciler
(
id CHAR(3) PRIMARY KEY,
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',99);
SELECT * FROM ogrenciler;
/* ---------------- Child Table ---------------- */
CREATE TABLE notlar
(
ogrenci_id CHAR(3),
ders_adi VARCHAR(30),
yazili_notu INT
);
/* Data insertion */
INSERT INTO notlar VALUES ('101','Kimya',75);
INSERT INTO notlar VALUES ('102','Fizik',65);
INSERT INTO notlar VALUES ('103','Tarih',90);
INSERT INTO notlar VALUES ('104','Matematik',90);