Professional Documents
Culture Documents
A basic university database is created. It has four relations: students, courses, departments and
registrations. Commands used to create these relations and the generated schema are given below.
1
MTL710 : Course Assignment
type
-----------number(38)
varchar2(20)
varchar2(20)
number(38)
char(25)
number(10)
DESC courses
Name
NULL?
type
----------------------------------------- -------- --------------------------id
NOT NULL number(38)
NAME
NOT NULL varchar2(20)
code
NOT NULL varchar2(10)
slot
NOT NULL char(1)
departmentid
NOT NULL number(38)
credits
NOT NULL number(38)
DESC
NAME
---id
NAME
code
department
NULL
type
-------- -----------NOT NULL number(38)
NOT NULL varchar2(20)
NOT NULL varchar2(4)
DESC registrations
NAME
NULL
type
--------- -------- ---------id
NOT NULL number(38)
studentid NOT NULL number(38)
courseid NOT NULL number(38)
2
MTL710 : Course Assignment
3
MTL710 : Course Assignment
Final Database:
SELECT command is used to get all the rows in a relation.
4
MTL710 : Course Assignment
SELECT firstname
FROM
students
WHERE id IN (SELECT studentid
FROM
registrations
WHERE courseid = 6);
Output:
5
MTL710 : Course Assignment
2. Update Command
A Query is written to update the address of student named Aditya to CTP-India
UPDATE students
SET
address = 'CTP-INDIA'
WHERE firstname = 'ADITYA';
Output:
3. Create a View
A Query is written to create a View containing students contact numbers
CREATE VIEW contacts_view
AS
SELECT firstname,
lastname,
phone
FROM
students;
Result:
6
MTL710 : Course Assignment
Output:
Case 1: No exception
Case 2: Exception
7
MTL710 : Course Assignment
Output:
8
MTL710 : Course Assignment