-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstraints.sql
More file actions
executable file
·50 lines (37 loc) · 928 Bytes
/
constraints.sql
File metadata and controls
executable file
·50 lines (37 loc) · 928 Bytes
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
USE accounts;
# Primary key Constraint
# CREATE TABLE test (
# id INT, # test (id) is a primary key s
# age INT,
# name VARCHAR(100),
# PRIMARY KEY (id,age)
# );
# Foreign Key Constraint
# CREATE TABLE temp (
# cityId INT,
# age INT NOT NULL,
# name VARCHAR(50),
# FOREIGN KEY (cityId) references test(id) # cityId is a foreign key
# );
CREATE TABLE temp2(
id INT,
name VARCHAR(100),
salary INT DEFAULT 30000,
PRIMARY KEY (id)
);
CREATE TABLE temp3 (
id INT,
name VARCHAR(100),
feespaid INT DEFAULT 0.00
);
INSERT INTO temp3 (id,name) VALUES(1,"Rishiraj");
INSERT INTO temp3 (id,name,feespaid) VALUES(2,"John",100000);
SELECT * FROM temp3;
# data for table temp2
INSERT INTO temp2 (id,name) VALUES(1,"Rishiraj");
INSERT INTO temp2 VALUES(2,"YASH",25000);
# data for table test
# INSERT INTO test VALUES(1,20,"RISHIRAJ");
# INSERT INTO test VALUES(2,20,"SHREYASH");
SELECT * FROM test;
SELECT * FROM temp2;