forked from benoirajan/s2-dbms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.sql
58 lines (47 loc) · 1.74 KB
/
2.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
58
date 22-03-22
a. create table dept(id int,name varchar(20),hod varchar(20));
Table created
create table emp(id int, name varchar(20),dept int, salary decimal);
Table created
b. insert into dept values(1,'D1','Rahul');
insert into dept values(2,'D2','Mathew');
insert into dept values(3,'D3','Ravi');
insert into dept values(4,'D4','Ejjas');
insert into dept values(5,'D5','John');
5 row created
insert into emp values(1, 'Eldo', '1', 50000);
insert into emp values(2, 'Bibi', '2', 40000);
insert into emp values(3, 'Raju', '3', 60000);
insert into emp values(5, 'Fasil', '4', 30000);
insert into emp values(4, 'Anit', '5', 10000);
5 row created
c. alter table dept add primary key(id);
Table altered
alter table emp add primary key(id),foreign key(dept) references dept(id);
Table altered
d.display
select * from emp;
ID NAME DEPT SALARY
---------- -------------------- ---------- ----------
1 Eldo 1 50000
2 Bibi 2 40000
3 Raju 3 60000
5 Fasil 4 30000
4 Anit 3 10000
select * from dept;
ID NAME HOD
---------- -------------------- --------------------
1 D1 Rahul
2 D2 Mathew
4 D4 Ejjas
3 D3 Ravi
e.update
update emp set salary = salary + 10000;
5 rows updated
update dept set hod = 'Ben Basil' where id=3;
1 row updated
f.delete
delete from emp where id = 5;
1 row deleted
delete from dept where id = 4;
1 row deleted