You are on page 1of 9

Name:Chenchu Aravind

Reg no:20MIA1126

Database Management systems

Writing Queries on views.

1. Create a view from single table containing all columns from the base
table.

create view view1 as (select * from student);

View created.

SQL> select * from view1;

REGNO SNAME CGPA SCHOOL


---------- --------------- ---------- ------------------------------
18bce1276 anmol 1.64 bharath
18bce1250 Aditya 1.98 sanford
18bce1107 aadi 1.78 st.puis
18bce1183 rohan 1.8 gvm
18bce1302 yash 1.96 narayana

2. Create a view from single table with selected columns.


SQL> create view view2 as (select regno,sname,cgpa,school from student);

View created.
SQL> select * from view2;

REGNO SNAME CGPA SCHOOL


---------- --------------- ---------- ------------------------------
18bce1276 anmol 1.64 bharath
18bce1250 Aditya 1.98 sanford
18bce1107 aadi 1.78 st.puis
18bce1183 rohan 1.8 gvm
18bce1302 yash 1.96 narayana

3. Create a view from two tables with all columns.


SQL> create view xyz as select * from student full natural join course;

View created.

SQL> select * from xyz;

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1276 anmol 1.64 bharath cse1001
programming 3

18bce1276 anmol 1.64 bharath cse1002


oops 3

18bce1276 anmol 1.64 bharath cse2004


dbms 4

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1276 anmol 1.64 bharath cse2001
dsb 4

18bce1276 anmol 1.64 bharath mat2002


apdd 3

18bce1250 Aditya 1.98 sanford cse1001


programming 3

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1250 Aditya 1.98 sanford cse1002
oops 3

18bce1250 Aditya 1.98 sanford cse2004


dbms 4
18bce1250 Aditya 1.98 sanford cse2001
dsb 4

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1250 Aditya 1.98 sanford mat2002
apdd 3

18bce1107 aadi 1.78 st.puis cse1001


programming 3

18bce1107 aadi 1.78 st.puis cse1002


oops 3

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1107 aadi 1.78 st.puis cse2004
dbms 4

18bce1107 aadi 1.78 st.puis cse2001


dsb 4
18bce1107 aadi 1.78 st.puis mat2002
apdd 3

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1183 rohan 1.8 gvm cse1001
programming 3

18bce1183 rohan 1.8 gvm cse1002


oops 3

18bce1183 rohan 1.8 gvm cse2004


dbms 4

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1183 rohan 1.8 gvm cse2001
dsb 4

18bce1183 rohan 1.8 gvm mat2002


apdd 3

18bce1302 yash 1.96 narayana cse1001


programming 3

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1302 yash 1.96 narayana cse1002
oops 3

18bce1302 yash 1.96 narayana cse2004


dbms 4

18bce1302 yash 1.96 narayana cse2001


dsb 4

REGNO SNAME CGPA SCHOOL CCODE


---------- --------------- ---------- ------------------------------ ----------
CNAME CREDITS
--------------- ----------
18bce1302 yash 1.96 narayana mat2002
apdd 3
25 rows selected.

4. Create a view from two tables with selected columns.


SQL> create view lmn3 as (select regno,cname,ccode,credits from
student,course where cgpa>1.0 and credits=3 );

View created.

SQL> select * from lmn3;

REGNO CNAME CCODE CREDITS


---------- --------------- ---------- ----------
18bce1276 programming cse1001 3
18bce1250 programming cse1001 3
18bce1107 programming cse1001 3
18bce1183 programming cse1001 3
18bce1302 programming cse1001 3
18bce1276 oops cse1002 3
18bce1250 oops cse1002 3
18bce1107 oops cse1002 3
18bce1183 oops cse1002 3
18bce1302 oops cse1002 3
18bce1276 apdd mat2002 3

REGNO CNAME CCODE CREDITS


---------- --------------- ---------- ----------
18bce1250 apdd mat2002 3
18bce1107 apdd mat2002 3
18bce1183 apdd mat2002 3
18bce1302 apdd mat2002 3

15 rows selected.

5. Check all DML commands with above 4 views.

SQL> insert into view1 values('20MIA1126','rajes','7.8','donbosco');

1 row created.
SQL> update view1 set cgpa=4.7 where regno like '18bce1276';

1 row updated.

SQL> select * from view1;

REGNO SNAME CGPA SCHOOL


---------- --------------- ---------- ------------------------------
18bce1276 anmol 4.7 bharath
18bce1250 Aditya 1.98 sanford
18bce1107 aadi 1.78 st.puis
18bce1183 rohan 1.8 gvm
18bce1302 yash 1.96 narayana
20MIA1126 rajes 7.8 donbosco

6 rows selected.
SQL> delete from view1 where school like 'gvm';

1 rows deleted.
6. Drop views which you generated.
SQL> drop view view1;

View dropped.

SQL> drop view view2


2 ;

View dropped.

SQL> drop view xyz;

View dropped.

You might also like