












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













**(Autonomous) (ISO/IEC - 27001 - 2013 Certified)
WINTER– 18 EXAMINATION Subject Name: Database Management System Model Answer** Subject Code: Important Instructions to examiners:
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ a. Physical level b. logical level c. view level
2. Data redundancy : The repetition of information is known as redundancy .This redundancy leads to higher storage and access cost. It may lead to data inconsistency, that is different copies of the same data may have different values. c Define the term: i) Candidate key ii) ii) Primary key
Ans Candidate key: In a relation, there may be a primary key or may not, but there may be a key or combination of keys which uniquely identify the record. Such a key is called as Candidate key. OR A candidate key is a column, or set of columns, in a table that can uniquely identify any database record without referring to any other data. The candidate key can be simple (having only one attribute) or composite as well. For Example, {STUD_NO, COURSE_NO} is a composite candidate key for relation STUDENT_COURSE. Primary key: A key which is selected by the designer to uniquely identify the entity is called as Primary key. A primary key cannot contain duplicate values and it can never contain null values inside it. Example, RollNo attribute is a primary key for Relation Student. 1 mark Candidate key 1 mark Primary Key d List Four DDL commands with syntax. 2 M Ans DDL commands
1. 1.Create Syntax : create table <table_name>(Column_name1 datatype1, column_name Datatype2,…Column_nameN DatatypeN); 2. Drop 1/2 mark for each command and ½ mark for syntax
**(Autonomous) (ISO/IEC - 27001 - 2013 Certified)
Ans Cursor:** The Oracle Engine uses a work area for its internal processing in order to execute an SQL statement. This work area is private to SQL‟s operations and is called a Cursor. OR A cursor is a temporary work area created in the system memory when a SQL statement is executed. Types of cursor are:
Hierarchical model is not more popular than network model Network model is more popular than the hierarchical and relational model.
It does not uses client server architecture It uses client – server architecture
One to many relationship is maintained. One to many and many to many relationship is maintained.
Hierarchical model is based on tree like structure with one root. Network model is based on tree like structure with many roots.
One child or many children have only one parent Many children have many parent
Main application of hierarchical model is in the mainframe database system. It is upgraded version of hierarchical model so used in network any 4 points b Explain set Operators with example. 4 M Ans Set operators combine the results of two component queries into a single result. Queries containing set operators are called as compound queries. Set operators in SQL are represented with following special keywords as: Union, Union all, intersection & minus. Consider data from two tables emp and employee as 1 mark for explanation and 1 mark for example each
**(Autonomous) (ISO/IEC - 27001 - 2013 Certified)
Emp Employee
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ Output: rajesh ii) Upper(char)- Returns the input string with all letters in upper case. Example: SQL>Select upper (‘rajesh’) from dual; Output: RAJESH iii) Ltrim(char,set)- It removes or trims from left of character string
. Example: SQL>Select Ltrim(‘university’,’univ’) from dual; Output: ersity iv) Rtrim(char,set)- It removes or trims from right of character string. Example: SQL>Select Rtrim(‘university’,’sity’) from dual; Output: univer v) Length(char)- It returns length of character string. Example: SQL> Select length(‘University’) from dual; Output: vi) Concat(str1,str2,...)- Returns the string that result from concatenating the arguments. Example: Select Concat(‘employee’, ‘name’) from dual; Output: employeename vii) Lpad(str, len, padstr)- Returns the string str, left-padded with the string padstr to a length of len characters. Example: Select lpad(ename,10.’’) from emp where empno=7782; viii) Rpad(str,len,padstr)- Returns the string str, right-padded with the string padstr to a length of len characters. Example: Select rpad(ename,10.’’) from emp where empno=7782;
**(Autonomous) (ISO/IEC - 27001 - 2013 Certified)
viii) Substr(Char,m,n)-** It returns a portion of char, beginning at a character m, n character long. Example: Select substr(‘College’,3,4) from dual; Output: lleg d Describe exception handling in brief. 4 M Ans Exception Handling: Exception is nothing but an error. Exception can be raise when DBMS encounters errors or it can be raised explicitly. When the system throws a warning or has an error it can lead to an exception. Such exception needs to be handled and can be defined internally or user defined. Exception handling is nothing but a code block in memory that will attempt to resolve current error condition. **Syntax: DECLARE ; Declaration section …executable statement; EXCEPTION WHEN ex_name1 THEN ; Error handling statements/user defined action to be carried out; END; Types of Exception:
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ Syntax: SELECT tablename.column1_name,tablename.column1_name FROM table_name1,table_name where table_name1.column_name=table_name2.column_name; Example: Select stud_info.stud_name, stud_info.branch_code, branch_details.location From stud_info, branch_details Where Stud_info.branch_code=branch_details.branch_code; 2) SELF JOIN: The SQL SELF JOIN is used to join a table to itself, as if the table were two tables, temporarily renaming at least one table in the SQL statement. Syntax: SELECT a.column_name, b.column_name FROM table1 a, table1 b WHERE a.common_filed = b.common_field; Example: Select x.stud_name, y.stud_name from stud_info x, stud_info y Where x.leader= y.stud_id; 3) LEFT OUTER JOIN: A left outer join retains all of the rows of the “left” table, regardless of whether there is a row that matches on the “right” table. Syntax: Select column1name,column2name from table1name any_alias1 ,table2name any_alias on any_alias1.columnname(+) = any_alias2.columnname; OR
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ Select column1name,column2name from table1name left outer join table2name on table1name.columnname= table2name.columnname; Example: select last_name, department_name from employees e, departments d on e.department_id(+) = d.department_id; OR select last_name, department_name from employees left outer join departments on employees.department_id = departments.department_id; 4) RIGHT OUTER JOIN: A right outer join retains all of the rows of the “right” table, regardless of whether there is a row that matches on the “left” table. Syntax: Select column1name, column2name from table1name any_alias1, table2name any_alias on any_alias1.columnname =any_alias2.columnname (+); OR Select column1name, column2name from table1name any_alias1 right outer join table2 name any_alias on any_alias1.columnname =any_alias2.columnname; Example: Select last_name,department_name from employees e, departments d on e.department_id = d.department_id(+); OR
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ Where, function-name specifies the name of the function. [OR REPLACE] option allows the modification of an existing function. The optional parameter list contains name, mode and types of the parameters. IN represents the value that will be passed from outside and OUT represents the parameter that will be used to return a value outside of the procedure. The function must contain a return statement. The RETURN clause specifies the data type you are going to return from the function. function-body contains the executable part. The AS keyword is used instead of the IS keyword for creating a standalone function. Example: CREATE OR REPLACE FUNCTION Success_cnt RETURN number IS cnt number(7) := 0; BEGIN SELECT count(*) into cnt FROM candidate where result='Pass'; RETURN cnt; END; / d Explain database security with its requirements in detail. 4 M Ans Database security Database security refers to the collective measures used to protect and secure a database or database management software from illegal use and malicious threats and attacks. Requirements of Database Security:
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ be able to view data they are not entitled to.
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ Example: In the above relation NAME, LOCATION depends on SNO and QTY on (SNO, PNO) so the table can be split up into two tables as Supplier(SNO,SNAME,LOCATION) and SP(SNO,PNO,QTY) and now both the tables are in second normal form. Supplier SNO SNAME LOCATION S1 Abc Mumbai S2 Pqr Pune S3 Lmn Delhi Supplier_Product SNO PNO QTY S1 P1 200 S2 P2 300 S3 P1 400 c Draw the block structure of PL/SQL. List advantages of PL/SQL. 4 M Ans (^) Declare (Optional) --Use for declaring variables Begin (Mandatory) --Use for writing executable code; Exception (Optional) --Use to write exceptions to be catch during run time. End; (Mandatory) --To terminate PL-SQL block/ code. For block structure - 2 Marks, For advantages - 2 Marks
**(Autonomous) (ISO/IEC - 27001 - 2013 Certified)
Advantages of PL/SQL:**
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ where emp_city=’Pune’ or emp_city=’Nagpur’ ii) Change the employee name ‘Ayush’ to ‘Ayan’ update Employee set emp_name=’Ayan’ where emp_name=’Ayush’ iii) Display the total number of employee whose dept is 50 Select count(*) from Employee where emp_dept=50; c Consider the following schema Depositor (ACC_no, Name, PAN, Balance). Create a view on Depositor having attributes(ACC_No,PAN) where balance is greater than 100000
Ans create view v as select ACC_No,PAN from Depositor where balance > 100000; Correct logic 3M, Correct syntax :3M 6 Attempt any TWO of the following : 12 M a Create a sequence i) Sequence name is Seq_1, Start with 1, increment by 1, minimum value 1, maximum value 20. ii) Use a seq_1 to insert the values into table Student( ID Number(10), Name char (20)); iii) Change the Seq_1 max value 20 to 50. iv) Drop the sequence.
Ans i)^ create sequence Seq_1 start with 1 increment by 1 minvalue 1 maxvalue 20; ii) insert into student values(Seq_1.nextval,’ABC’); Query 1: 2M, Query 2: 2M, Query 3 : 1M, Query 4 : 1M
(Autonomous) (ISO/IEC - 27001 - 2013 Certified) __________________________________________________________________________________________________ iii) Alter sequence Seq_1 maxvalue 50; iv) Drop sequence Seq_1; b Write a PL/SQL program which accepts the customer_ID from the user. If the enters an invalid ID then the exception invalid_id is raised using exception handling.
Ans DECLARE c_id numeric(10); invalid_id_Exception Exception; BEGIN c_id:=&c_id; if(c_id<0) then raise invalid_id_Exception; end if; EXCEPTION WHEN invalid_id_Exception THEN dbms_output.put_line('Invalid customer id'); END; Correct logic : 3M, Correct syntax : 3M c i) create user ‘Rahul’ ii) grant create, select,insert,update, delete, drop privilege to ‘Rahul’ iii) Remove the select privilege from user ‘Rahul’
Ans (i) create user Rahul identified by rahul1234; (ii)