Professional Documents
Culture Documents
Declaration :
I declare that this assignment is my individual work. I have not copied from any other student’s work
or from any other source except where due acknowledgement is made explicitly in the text,nor has
any part been written for me by another person.
Evaluator’s comments :
___________________________________________________________________________
Joins:
Using more than a single table of a database is usually essential.The basic form is just to list
all the needed tables in the from line.We do have to explain to the DBMS how the tables
should be joined together. The JOIN keyword is used in an SQL statement to query data from
two or more tables, based on a relationship between certain columns in these tables.
• JOIN: Return rows when there is at least one match in both tables
• LEFT JOIN: Return all rows from the left table, even if there are no matches in the
right table
• RIGHT JOIN: Return all rows from the right table, even if there are no matches in
the left table
• FULL JOIN: Return rows when there is a match in one of the tables
Since joins allow to access data from two or more tables they really are of importance
in DBMS.
Views:
Unlike ordinary tables (base tables) in a relational database, a view does not form part of the
physical schema: it is a dynamic, virtual table computed or collated from data in the database.
A SQL View is a virtual table, which is based on SQL SELECT query. Essentially a view is
very close to a real database table (it has columns and rows just like a regular table), except
for the fact that the real tables store data, while the views don’t. The view’s data is generated
dynamically when the view is referenced. A view references one or more existing database
tables or other views. In effect every view is a filter of the table data referenced in it and this
filter can restrict both the columns and the rows of the referenced tables.
Here is an example of how to create a SQL view using already familiar Product and
Manufacturer SQL tables:
A view can be referenced and used from another view, from a SQL query, and from stored
procedure. You reference a view as you would reference any real SQL database table:
Both the joins and views have their importance in DBMS and play a important role in
DBMS.
to find those tuples pertaining to loans of more than $1250 made by the Jalandhar branch, we
write
σbranch-name =“Perryridge”∧ amount>1250 (loan)
loan-number branch-name amount
L-15 Jalandhar 1500
L-16 Jalandhar 1300
Relational calculus:
Relational calculus consists of two calculi, the tuple relational calculus and the domain
relational calculus, that are part of the relational model for databases and provide a
declarative way to specify database queries. This in contrast to the relational algebra which is
also part of the relational model but provides a more procedural way for specifying queries.
The relational algebra and the relational calculus are essentially logically equivalent: for any
algebraic expression, there is an equivalent expression in the calculus, and vice versa.
Example: Finding the loan number for each loan of an amount greater than $1400
{t | ∃ s ∈ loan (t[loan-number] = s[loan-number]∧ s[amount] > 1400)
Q. 3 “Does indexing play a role in database management system”. Explain your answer
with example.
Ans.
An index can be defined as a small table which has only two columns. The first column
contains a copy of the primary or candidate key of a table and the second column contains a
set of pointers holding the address of the disk block where that particular key value can be
found.
The main advantage of indexing lies is that index makes search operation perform very fast.
Example:Let us consider a table has a several rows of data, each row is 10 bytes wide. If you
want to search for the record number 70, the management system must thoroughly read each
and every row and after reading 99x10 = 990 bytes it will find record number 70. If we have
an index, the management system starts to search for record number 70 not from the table,
but from the index. The index, containing only two columns, may be just 4 bytes wide in each
of its rows. After reading only 99x4 = 396 bytes of data from the index the management
system finds an entry for record number 70, reads the address of the disk block where record
number 70 is stored and directly points at the record in the physical storage device. The result
is a much quicker access to the record (a speed advantage of 990:396).
Considering these advantages of indexing we must say that indexing not only plays role but
plays a vital role in database management system.
Part-B
Q.4Explain all the constraints of the SQl taking egs of two tables employee and dept?
1)Primary key
2)Foreign key
3)check
4)Not null
5)unique
Primary key: Whatever attribute we are going to create primary key can’t be left empty and
should be unique.
1 Row created.
2.)Foreign key:
Let’s create another table deptt in which emp_id is the foreign key.It means that value of
emp_id to be used in deptt table must present in employee table.
Table created.
3)Check:Using check constraint means that we are going to give some condition and that
condition should be fulfilled in order to successfully create table:
1)Employee table :To use check constraint in employee table it should be used while creating
the employee table.It will be like this:
Now if we insert emp_id that doen’t start with 1,the constraint will be violated.
2)Deptt table :
It means that if while inserting deptt_name in deptt table it should start with A or else
constraint will be violated.
4)NOT NULL:
5.UNIQUE
Applying this constraint means that a value used once can’t be repeated.
Employee table:
Deptt table:
Q. 5: write an SQL query without using a with clause , to find all branches where the
total account deposit is less than the average total account deposit at all branches
Department(dep_no, Dept_name,Location)
a) List all the employees whose location is ‘Pune’ and salary greater than 10000
Ans select * from employee,department where department.location=’pune’ and
employee.salary>10000;
b) Count the total number of departments. Also count the total number of
employees whose dept_name is ‘computer’
Ans.
Counting total no. of departments:
Select count(dept_name)from department as total_dept _nos from department;
Counting total number of employees whose dept_name is ‘computer’
c) You have forgot to put the primary key while creating table employee now make
emp_id as primary key
Ans. Alter table employee modify(emp_id number(10) primary key);
d) List the names of employees who work in department of sales
Ans. Select emp_name from department,employee where department.dept_name=’sales’;
e) List the names of employees having maximum and minimum salary
Ans. Select emp_name,max(salary),min(salary) from employee;
f) You want to change the name of some column say location to loc in dept table
how you will do it