CSE301 Homework: 2 DOA :-------------PART-A DOS

:---------------

Question 1: Why do we use indexing? Give a suitable example in support of your answer. Ans:- A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of slower writes and increased storage space. Some databases extend the power of indexing by allowing indexes to be created on functions or expressions. For example, an index could be created on upper(last_name), which would only store the upper case versions of the last_name field in the index. Another option sometimes supported is the use of "filtered" indexes, where index entries are created only for those records that satisfy some conditional expression. A further aspect of flexibility is to permit indexing on user-defined functions, as well as expressions formed from an assortment of built-in functions. Question 2: Under what circumstances, we will use foreign key? Give an example. Ans:-Foreign Key is used to make relation between two tables. The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.. A FOREIGN KEY in one table points to a PRIMARY KEY in another table. The following SQL creates a FOREIGN KEY on the "P_Id" column when the "Orders" table is created: CREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (O_Id), FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) ) Question3: Produces a new relation with some of the attributes of relation and remove duplicate tuples, give two different examples. . PART-B Question 4: Can we use a virtual table for security purpose? Justify your answer and give an example to create a view. Question 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 a) Using a nested query in the from clause

b)

Using a nested query in a Having clause ?

Question 6: Consider the table EMPLOYEE and Department with following fields: Employee( Emp_id,Emp_name, Dept_no, salary) Department(dep_no, Dept_name,Location) Perform the following computations on table data: a) List all the employees whose location is ‘Pune’ and dept_name is ‘Computer’. b) Count the total number of departments. Also count the total number of employees whose dept_name is ‘computer’ c) Add a new department ‘R&D’ in the database. d) List the names of employees whose salary is greater than 50000 and dept_ name is ‘computer'. e) List the names of employees having maximum and minimum salary f) Now change the department name from ‘computer’ to ‘software design’, wherever applicable in the table.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.