-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13. Constraints.sql
40 lines (24 loc) · 926 Bytes
/
13. Constraints.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
-- 1. Primary keyword
-- - used to uniquely identify the tuple/record/entry.
-- - NOT NULL, Unique, Only one PK
-- syntax -
id INT primary key
-- ,or
primary key (id)
-------------------------------------------------
-- 2. Foreign Key
-- it is referring to primary key of other table.
-- It maintains reference-integrity.
-- SYNTAX -
Foreign key cust_id references Customer(id)
-- REFERENCED TABLE - table with foreign key
-- REFERNCING TABLE - table where reference table is pointing to.
-------------------------------------------------
-- 3. UNIQUE keyword
-- it generally creates uniqueness to reduce/remove column-wise duplicacy.
------------------------------------------------------
-- 4. CHECK keyword.
-- it generally checks for certain condition during insertion of a file.
CONSTRAINT acc_balance CHECK (balance > 1000);
---------------------------------------------------------
5. Default..