0% found this document useful (0 votes)
29 views

Assignment 4

1. The document describes creating views, synonyms, sequences and indexes on tables in a database. 2. Steps include creating views to join tables, updating a view, creating synonyms for tables, altering a sequence, and creating indexes. 3. Queries are also provided to select data using joins, unions, minuses and intersections between tables.

Uploaded by

subhajitbasak001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Assignment 4

1. The document describes creating views, synonyms, sequences and indexes on tables in a database. 2. Steps include creating views to join tables, updating a view, creating synonyms for tables, altering a sequence, and creating indexes. 3. Queries are also provided to select data using joins, unions, minuses and intersections between tables.

Uploaded by

subhajitbasak001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSIGNMENT 4

l.Create a View 'v header' from the table route_header

Update the view to set fare=42.00 where route id=02.

3. Create a view 'vrr route header and route detail from route header and
route_detail with the following column: route_id, origin, destination, fare,
place id, non_stop.

4. Create a synonym for the table ticket_header with the name"tick".

5. Create a sequence 'ticseq' with the following specification:


minimum value=l,
max value=20,
Increase=l ,
Start with=l
With cycle and cache memory—10.

6. Alter the sequence such that the max value would be 25.

7. Create a normal index 'tickin' on adult column of the ticket header.

1. SQL> CREATE VIEW V_HEADER AS SELECT * FROM

ROUTE_HEADER; View created.

SQL> SELECT * FROM V_HEADER;

ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION


---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------
101 33 1 Madurai Madras
35 250 50

102 25 2 Trichy Madurai


40 159 50

ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION


---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------
103 15 3 Thanjavur Madurai
59 140 50

105 40 1 Bangalore Madras


80 375 50

ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION


---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------

106 38 2 Madras Madurai


39 300 50

107 39 3 Hyderabad Madras

ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION


---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------
50 430 50

108 41 4 Madras Cochin


47 576 50
7 rows selected.

2.

SQL> UPDATE V_HEADER SET FARE=42.00 WHERE ROUTE_ID=102;

1 row updated.

3.

SQL> UPDATE V_HEADER SET FARE=42.00 WHERE ROUTE_ID=102;

1 row updated.

4.

SQL> CREATE VIEW VRR_ROUTE_HEADER AS SELECT


2 A.ROUTE_ID,
3 A.ORIGIN,
4 A.DESTINATION,
5 A.FARE,
6 B.PLACE_ID,
7 B.NONSTOP FROM ROUTE_HEADER A,
8 ROUTE_DETAIL B WHERE A.ROUTE_ID=B.ROUTE_ID;View created.

5. SQL> CREATE SYNONYM TICK FOR

TICKET_HEADER; Synonym created.

SQL> SELECT * FROM TICK;

FLEET_ID TICKET_NO DATE_OF_T TIME_TRA BOARD_PLACE


---------- ---------- --------- -------- --------------------
ORIGIN DESTINATION ADULTS CHILDREN TOTAL_FARE
-------------------- -------------------- ---------- ---------- ----------
ROUTE_ID DATE_OF_B
---------- ---------
2 2 08-APR-10 09:00:00 KK Nagar
Madurai Madras 2 1 60
102 08-FEB-10

3 3 08-APR-10 21:00:00 Cubbonpark


Bangalore Madras 4 2 400
101 08-FEB-10

FLEET_ID TICKET_NO DATE_OF_T TIME_TRA BOARD_PLACE


---------- ---------- --------- -------- --------------------
ORIGIN DESTINATION ADULTS CHILDREN TOTAL_FARE
-------------------- -------------------- ---------- ---------- ----------
ROUTE_ID DATE_OF_B
---------- ---------

4 4 08-APR-10 10:00:00 Charminar


Hyderabad Madras 10 0 500
103 08-FEB-10

SQL> CREATE SEQUENCE TICSEQ INCREMENT BY 2 START WITH 1 MAXVALUE 20 MINVALUE 0


CYCLE CACHE 10;

Sequence created.

6. SQL> ALTER SEQUENCE TICSEQ

MAXVALUE 25; Sequence altered.

7.

SQL> CREATE INDEX TICKIN ON TICKET_HEADER(ADULTS);

Index created.

SQL> COMMIT;

Commit complete.
ASSIGNMENT 4b
Q8. Select distinct numbers from both ticket_header and
ticket_detail.
Q9. Select all ticket numbers from ticket_header and
ticket_detail.
Q10. Select distinct route_id from route_header and not in
route_detail using both the tables.
Q11. Select all rows from route_header and only matching rows
from route_detail.
Q12. Select distinct route_ids from route_header and
route_detail.
Q13. Select only common place ids that are present in
place_header and route_detail.
Q14. Select common ticket numbers from ticket_header and
ticket_detail where the route ids are greater than the route_id
which belong to the place with iod ‘02’.

8.

SQL> (SELECT DISTINCT(TICKET_NO) FROM TICKET_HEADER) UNION (SELECT


DISTINCT(TICKET_NO) FROM TICKET_DETAIL);

TICKET_NO
----------
1
2
3
4
5

9.

SQL> (SELECT TICKET_NO FROM TICKET_HEADER) UNION ALL (SELECT TICKET_NO FROM
TICKET_DETAIL);

TICKET_NO
----------
2
3
4
1
1
2
2
2
5
10.

SQL> (SELECT DISTINCT(ROUTE_ID) FROM ROUTE_HEADER) MINUS (SELECT


DISTINCT(ROUTE_ID) FROM ROUTE_DETAIL);

ROUTE_ID
----------
101
103
107

11.

SQL> SELECT * FROM TICKET_HEADER X WHERE X.ROUTE_ID<X.TICKET_NO;

no rows selected

12.

SELECT * FROM ROUTE_HEADER,ROUTE_DETAIL WHERE


ROUTE_HEADER.ROUTE_ID=ROUTE_DETAIL.ROUTE_ID;

ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION


---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------
ROUTE_ID PLACE_ID N
---------- ---------- -
102 25 2 Trichy Madurai
42 159 50

102 2 S

ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION


---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------
ROUTE_ID PLACE_ID N
---------- ---------- -
105 40 1 Bangalore Madras
80 375 50

105 1 N
ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION
---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------
ROUTE_ID PLACE_ID N
---------- ---------- -
106 38 2 Madras Madurai
39 300 50

106 1 S

ROUTE_ID ROUTE_NUMBER CAT_CODE ORIGIN DESTINATION


---------- ------------ ---------- -------------------- --------------------
FARE DISTANCE CAPACITY
---------- ---------- ----------
COMMENTS
--------------------------------------------------------------------------------
ROUTE_ID PLACE_ID N
---------- ---------- -
108 41 4 Madras Cochin
47 576 50

108 5 N

13.

SQL> (SELECT PLACE_ID FROM ROUTE_DETAIL) INTERSECT (SELECT PLACE_ID FROM


ROUTE_DETAIL);

PLACE_ID
----------
1
2
5

14.

SQL> (SELECT TICKET_NO FROM TICKET_HEADER WHERE ROUTE_ID>02) INTERSECT (SELECT


TICKET_NO FROM TICKET_DETAIL);

TICKET_NO
----------
2

SQL> COMMIT;

Commit complete.

You might also like