DBMS Assignment1 & 2
DBMS Assignment1 & 2
Data Type
Varchar2
Number
Varchar2
Varchar2
Number
Number
Varchar2
Number
Date
Size
6
6
10
15
10
4
4
1
Constraints
Not null
Not null
Not null
Not null
Not null
Not null
Not null
Not null
RegNo
RollNo
Name
Address
PhoneNo
YearOfAdm
012301
123001
Ashish
Jadavpur
012315
123015
Kamal
Kasba
012424
124024
Ipsita
Kaikhali
012250
122050
Anita
Hooghly
2476189
2
2442498
7
2573960
8
3671969
5
012344
012357
123044
123057
Biplab
Samik
Howrah
Barasat
2542674
2
Year
BirthDate
2003
DeptCod
e
CSE
01-Jun-81
2003
CSE
19-Sep-81
2004
CSE
15-Aug-82
2002
IT
22-Dec-80
2003
2003
IT
IT
3
3
03-Jan-82
15-Jul-81
012419
124019
Srija
Garia
2475565
5
2475330
6
012427
124027
Saibal
Garia
012236
122036
Santanu
012349
123049
Gita
DumDu
m
Kasba
2442868
2
2004
EE
25-Oct-82
2004
ECE
22-Mar-83
2002
ECE
11-Dec-80
2003
MCA
14-Apr-81
ADDRESS
2003
CSE
12315
123015
19-SEP-81
Kamal
Kasba
24424987
2003
CSE
12424
124024
15-AUG-82
Ipsita
Kaikhali
25739608
2004
CSE
12250
122050
22-DEC-80
Anita
Hooghly
36719695
2002
IT
12357
123057
15-JUL-81
Samik
Barasat
25426742
2003
IT
12419
124019
25-OCT-82
Srija
Garia
24755655
2004
EE
12427
124027
22-MAR-83
Saibal
Garia
24753306
2004
ECE
12349
123049
14-APR-81
Gita
Kasba
24428682
2003
MCA
12344
123044
03-JAN-82
Biplab
Howrah
23345678
2003
IT
12236
122036
11-DEC-80
Santanu
DumDum
2002
ECE
Srija
Garia
Saibal
Garia
Gita
Kasba
Biplab
Howrah
Santanu DumDum
2004
2004
2003
2003
2002
10 rows selected.
5. List the name and year of students who are in Computer Science.
SQL> select Name,Year from student41612
where DeptCode='CSE';
NAME
YEAR
---------- ---------Ashish
3
Kamal
3
Ipsita
2
6. List the names and departments of students belonging to 3rd year.
SQL> select Name,DeptCode from student4161
2 where Year=3;
NAME
DEPT
---------- ---Ashish
CSE
Kamal
CSE
Samik
IT
Gita
MCA
Biplab
IT
7. Display names of students with a as
the second letter in their names.
Saibal
Santanu
For patterns to include the special pattern characters (that is, % and), SQL allows the
specification of an escape character. The escape character is used immediately
before a special pattern character to indicate that the special pattern character is to
be treated like a normal character.
Example1
To check for the string '15%', we can use the predicate:
LIKE '15#%' ESCAPE '#' matches the string 15%
Example2
like ab#%cd% escape \ matches all strings beginning with ab%cd.
Example3
like ab\\cd% escape \ matches all strings beginning with ab\cd.
10. List the names of students who do not have a phone number.
SQL> select Name from student41612
where PhoneNo is NULL;
NAME
---------Biplab
Santanu
Delete operations.
a) remove all rows
delete from <tablename>;
b) removal of a specified row/s
delete from <tablename> where <condition>;
Assignment-2
1) Delete the name of a student whose roll no, year and department code is given
delete from student4161
where RollNo=122050 AND Year=4 AND DeptCode='IT';
2) Display the number of students in each department.
SQL> select DeptCode, count(*) from student41612 group by DeptCode;
DEPT COUNT(*)
---- ---------CSE
3
ECE
2
EE
1
IT
2
MCA
1
Syntax:
Update <tablename> set
<col>=<exp>,<col>=<exp>;
update account
set balance = balance * 1.05
Syntax:
Update <tablename> set
<col>=<exp>,<col>=<exp>
where <condition>;
case
when pred1 then result1
when pred2 then result2
...
when predn then resultn
else result0
end
update account
set balance = balance * 1.05
where balance >= 1000
update account
set balance = case
when balance <= 10000 then balance *
1.05
else balance * 1.06
end
UPDATE
SET
WHERE
PROJECT
PLOCATION = 'Bellaire', DNUM = 5
PNUMBER=10;
UPDATE staff
SET position = 'Manager', salary =
18000
WHERE sno = 'SGI4';
Table altered.
SQL> Update student4161
2 set ColPhone=25739607;
9 rows updated.
2.
Samik
Srija
Saibal
Santanu
Gita
80
70
85
85
75
9 rows selected.
8) Drop column MarksObtained from table student.
Alter table student4161
drop(Marks);