-
Notifications
You must be signed in to change notification settings - Fork 0
/
referentialintegrity.sql
60 lines (46 loc) · 1009 Bytes
/
referentialintegrity.sql
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
--PARENT TABLE--
CREATE TABLE CUSTOM(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
PRIMARY KEY (ID)
);
--INSERTING RECORDS--
INSERT INTO CUSTOM
(ID,NAME,AGE)VALUES(1,'SAM',23);
INSERT INTO CUSTOM
(ID,NAME,AGE)VALUES(2,'SAMS',23);
INSERT INTO CUSTOM
(ID,NAME,AGE)VALUES(3,'SAMF',23);
--DISPLAY RECORDS--
SELECT * FROM CUSTOM;
--CHILD TABLE--
CREATE TABLE ORDEd (
ID INT NOT NULL,
CUSTOMER_ID INT references CUSTOMERS(ID),
AMOUNT number,
PRIMARY KEY (ID)
);
--INSERTING RECORDS--
INSERT INTO ORDEd
(ID,CUSTOMER_ID,AMOUNT)VALUES(1,1,2003);
INSERT INTO ORDEd
(ID,CUSTOMER_ID,AMOUNT)VALUES(2,2,20303);
INSERT INTO ORDEd
(ID,CUSTOMER_ID,AMOUNT)VALUES(3,3,20203);
--DISPLAY RECORDS IN CHILD TABLE--
SELECT * FROM ORDEd;
--SCHEMA PRACTICE--
SELECT C.NAME,C.AGE,O.AMOUNT
FROM CUSTOM C
JOIN ORDED O
ON C.ID=O.ID;
--SCHEMA PRACTICE--
SELECT C.NAME,O.AMOUNT,O.CUSTOMER_ID
FROM CUSTOM C
JOIN ORDED O
ON C.ID=O.ID;
SELECT C.NAME,O.AMOUNT
FROM CUSTOM C
JOIN ORDED O
ON C.ID=O.ID;