dbms questions

24
DBMS QUESTIONS 1. What is database? A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose. 2. What is DBMS? It is a collection of programs that enables user to create and maintain a database. In other words it is general- purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications. 3. What is a Database system? The database and DBMS software together is called as Database system. 4. Advantages of DBMS? Ø Redundancy is controlled. Ø Unauthorised access is restricted. Ø Providing multiple user interfaces. Ø Enforcing integrity constraints. Ø Providing backup and recovery. 5. Explain the difference between an explicit and an implicit lock. Explicit Lock: - Lock is explicitly requested for a record or table.

Upload: kavitha-neelakandan

Post on 21-Nov-2014

185 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Dbms Questions

DBMS QUESTIONS

1. What is database?

A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose.

2. What is DBMS?

It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications.

3. What is a Database system?

The database and DBMS software together is called as Database system.

4. Advantages of DBMS?

Ø Redundancy is controlled.

Ø Unauthorised access is restricted.

Ø Providing multiple user interfaces.

Ø Enforcing integrity constraints.

Ø Providing backup and recovery.

5. Explain the difference between an explicit and an implicit lock.

Explicit Lock: - Lock is explicitly requested for a record or table.

Implicit Lock: - Lock is implied but is not acquired

6. Explain the difference between a database administrator and a data administrator.

Database Administrator :- A person (or group of people) responsible for the maintenance and performance of a database and responsible for the planning, implementation, configuration, and administration of relational database management systems.

Data Administrator :- The individual or organization responsible for the specification, acquisition, and maintenance of data management software and the design, validation,

Page 2: Dbms Questions

and security of files or databases. The DA is in charge of the data dictionary and data model.

7. What is lock granularity?

Locking granularity refers to the size and hence the number of locks used to ensure the consistency of a database during multiple concurrent updates.

8. Define the "integrity rules"

There are two Integrity rules.

Entity Integrity: States that “Primary key cannot have NULL value”

Referential Integrity: States that “Foreign Key can be either a NULL value or should be Primary Key value of other relation.

9. What is Data Model?

A collection of conceptual tools for describing data, data relationships data semantics and constraints.

10. What is E-R model?

This data model is based on real world that consists of basic objects called entities and of relationship among these objects. Entities are described in a database by a set of attributes.

11. What is Object Oriented model?

This model is based on collection of objects. An object contains values stored in instance variables with in the object. An object also contains bodies of code that operate on the object. These bodies of code are called methods. Objects that contain same types of values and the same methods are grouped together into classes.

12. What is an Entity?

It is a 'thing' in the real world with an independent existence.

13. What is an Entity type?

It is a collection (set) of entities that have same attributes.

14. What is an Entity set?

Page 3: Dbms Questions

It is a collection of all entities of particular entity type in the database.

15. What is an Extension of entity type?

The collections of entities of a particular entity type are grouped together into an entity set.

16. What is Weak Entity set?

An entity set may not have sufficient attributes to form a primary key, and its primary key compromises of its partial key and primary key of its parent entity, then it is said to be Weak Entity set.

17. What is an attribute?

It is a particular property, which describes the entity.

18. What is a Relation Schema and a Relation?

A relation Schema denoted by R(A1, A2, …, An) is made up of the relation name R and the list of attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation which contains set tuples (t1, t2, t3, ..., tn). Each tuple is an ordered list of n-values t=(v1,v2, ..., vn).

19. What is degree of a Relation?

It is the number of attribute of its relation schema.

20. What is Relationship?

It is an association among two or more entities.

21. What is Relationship set?

The collection (or set) of similar relationships.

22. What is Relationship type?

Relationship type defines a set of associations or a relationship set among a given set of entity types.

23. What is degree of Relationship type?

It is the number of entity type participating.

24. What is DDL (Data Definition Language)?

Page 4: Dbms Questions

A data base schema is specifies by a set of definitions expressed by a special language called DDL.

26. What is VDL (View Definition Language)?

It specifies user views and their mappings to the conceptual schema.

27. Describe the three levels of data abstraction?

The are three levels of abstraction:

Ø Physical level: The lowest level of abstraction describes how data are stored.

Ø Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data.

Ø View level: The highest level of abstraction describes only part of entire database.

28. What is normalization?

It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs) and primary key to achieve the properties

Ø Minimizing redundancy

Ø Minimizing insertion, deletion and update anomalies.

29. What is 1 NF (Normal Form)?

The domain

of attribute must include only atomic (simple, indivisible) values.

30. What is Fully Functional dependency?

It is based on concept of full functional dependency. A functional dependency X Y is full functional dependency if removal of any attribute A from X means that the dependency does not hold any more.

31. What is 2NF?

A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully functionally dependent on primary key.

32. What is 3NF?

Page 5: Dbms Questions

A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the following is true

Ø X is a Super-key of R.

Ø A is a prime attribute of R.

In other words, if every non prime attribute is non-transitively dependent on primary key.

33. What is BCNF (Boyce-Codd Normal Form)?

A relation schema R is in BCNF if it is in 3NF and satisfies an additional constraint that for every FD X A, X must be a candidate key.

34. What is meant by query optimization?

The phase that identifies an efficient execution plan for evaluating a query that has the least estimated cost is referred to as query optimization.

35. What is system catalog or catalog relation? How is better known as?

A RDBMS maintains a description of all the data that it contains, information about every relation and index that it contains. This information is stored in a collection of relations maintained by the system called metadata. It is also called data dictionary.

36. Explain the difference between a database administrator and a data administrator.

Database Administrator :- A person (or group of people) responsible for the maintenance and performance of a database and responsible for the planning, implementation, configuration, and administration of relational database management systems.

Data Administrator :- The individual or organization responsible for the specification, acquisition, and maintenance of data management software and the design, validation, and security of files or databases. The DA is in charge of the data dictionary and data model.

37. In general, how should the boundaries of a transaction be defined?

A transaction ensures that one or more operations execute as an atomic unit of work. If one of the operations within a transaction fails, then all of them are rolled-back so that the application is returned to its prior state. The boundaries that define a group of operations done within a single transaction.

Page 6: Dbms Questions

38. Explain the meaning of the expression ACID transaction.

ACID means Atomic, Consistency, Isolation, Durability.

ATOMICITY: when any transaction happen it should be Atomic that is it should either be complete or fully incomplete. There should not be anything like Semi complete.

CONSISTENT: The Database State should remain consistent after the completion of the transaction.

ISOLATION: If there are more than one Transaction then the transaction should be scheduled in such a fashion that they remain in Isolation of one another.

DURABILITY: Durability means that Once a transaction commits, its effects will persist even if there are system failures.

39. Explain the necessity of defining processing rights and responsibilities. How are such responsibilities enforced?

One of the reason to define rights is the security in the database system. If any user is allowed to define the data or alter the data then the database would just be of no use and so processing rights and responsibilities are clearly defined in any database system. The resposibilities are enforced using the table space provided by the database system.

40. Describe the advantages and disadvantages of DBMS-provided and application-provided security.

DBMS provided security :- Any database system requires you to login and then process the data depending on the rights given by the DBA to the user who has logged in. The advatage of such a system is securing the data and providing the user and the DBA the secured platform. Any user who logs in cannot do whatever he want but his role can be defined very easily. There is no major disadvantage about the DBMS provided security apart from overhead of storing the rights and priviledges about the users.

Application-provided security :- It is much similar to the DBMS provided security but the only difference is that its the duty of the programmer creating the application to provide all the seurities so that the data is not mishandled.

Page 7: Dbms Questions

41. Explain how a database could be recovered via reprocessing. Why is this generally not feasible?

If we reprocess the transaction then the database can be made to come to a state where the database is consistent and so reprocessing the log can recover the database. Reprocessing is not very feasible for a very simple reason that its very costly from time point of view and requires lots of rework and many transaction are even rollback giving more and more rework.

42.Define rollback and roll forward.

Rollback :- Undoing the changes made by a transaction before it commits or to cancel any changes to a database made during the current transaction

RollForward :- Re-doing the changes made by a transaction after it commits or to overwrite the chnaged calue again to ensure consistency

43. Why is it important to write to the log before changing the database values?

The most important objective to write the log before the database is changed is if there is any need to rollback or rollforward any transaction then if the log are not present then the rollback rollforward cannot be done accurately.

44. what is the difference between DBMS and RDBMS??

i) In DBMS Normalization process wille not be present and in RDBMS normalization process will be present to check the database table cosistency

ii) DBMS is a ordinary system to maintain the data, whereas RDBMS is the specific type, which follows the concepts of set theory i.e entity etc.

iii) In DBMS there is no concept of PRIMARY KEY and FOREIGN KEY but it is included in RDBMS.

iv) DBMS contains only flat data whereas in RDBMS there will be some relation between the entities.

Questions and Answers on DBMS, Oracle, SQL and PL/SQL

45. What are the wildcards used for pattern matching.

Page 8: Dbms Questions

Answer: _ for single character substitution and % for multi-character substitution.

46.How can I hide a particular table name of our schema?

Answer: you can hide the table name by creating synonyms.

e.g) you can create a synonym y for table x

create synonym y for x;

47. When we give SELECT * FROM EMP; How does oracle respond:

Answer: When u give SELECT * FROM EMP;

the server check all the data in the EMP file and it displays the data of the EMP file

48.What is the use of CASCADE CONSTRAINTS?

Answer: When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.

SQL Server/Sybase :

Employee_table.Dept_id(+) = Dept_table.Dept_id

49. why u need indexing? Where that is stored and what u mean by schema object? For what purpose we are using view

Answer: We cant create an Index on Index. Index is stored in user_index table. Every object that has been created on Schema is Schema Object like Table, View etc. If we want to share the particular data to various users we have to use the virtual table for the Base table...So that is a view.

50.How to store directory structure in a database?

Answer: We can do it by the following command: create or replace directory as 'c: \tmp'

51.Why does the following command give a compilation error?

DROP TABLE &TABLE_NAME;

Page 9: Dbms Questions

Answer: Variable names should start with an alphabet. Here the table name starts with an '&' symbol.

52. Difference between VARCHAR and VARCHAR2?

Answer: Varchar means fixed length character data (size) i.e., min size-1 and max-2000

Varchar2 means variable length character data i.e., min-1 to max-4000

53.Which command displays the SQL command in the SQL buffer, and then executes it

Answer: You set the LIST or L command to get the recent one from SQL Buffer

54.Which system table contains information on constraints on all the tables created?

Answer: USER_CONSTRAINTS.

55.How do I write a program which will run a SQL query and mail the results to a group?

Answer: Use DBMS_JOB for scheduling a program job and DBMS_MAIL to send the results through email.

56.There is an Eno. & gender in a table. Eno. has primary key and gender has a check constraints for the values 'M' and 'F'.

While inserting the data into the table M was misspelled as F and F as M.

57.What is the update?

Answer: update <TableName> set gender=

case where gender='F' Then 'M' where gender='M' Then 'F'

58.What the difference between UNION and UNIONALL?

Answer: union will return the distinct rows in two select s, while union all return all rows.

59.How can we backup the sql files & what is SAP?

Page 10: Dbms Questions

Answer: You can backup the sql files through backup utilities or some backup command in sql. SAP is ERP software for the organization to integrate the software.

60.What is the difference between TRUNCATE and DELETE commands?

Answer: TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back.

WHERE clause can be used with DELETE and not with TRUNCATE.

61.State true or false. !=, <>, ^= all denote the same operation.

Answer: True.

62.State true or false. EXISTS, SOME, ANY are operators in SQL.

Answer: True.

63.What will be the output of the following query?

SELECT REPLACE (TRANSLATE (LTRIM (RTRIM ('!! ATHEN!!','!'), '!'), 'AN', '**'),'*','TROUBLE') FROM DUAL;

Answer: TROUBLETHETROUBLE.

64. What is the advantage to use trigger in your PL?

Answer: Triggers are fired implicitly on the tables/views on which they are created. There are various advantages of using a trigger. Some of them are:

Suppose we need to validate a DML statement (insert/Update/Delete) that modifies a table then we can write a trigger on the table that gets fired implicitly whenever DML statement is executed on that table.

- Another reason of using triggers can be for automatic updation of one or more tables whenever a DML/DDL statement is executed for the table on which the trigger is created.

- Triggers can be used to enforce constraints. For eg: Any insert/update/ Delete statements should not be allowed on a particular table after office hours. For enforcing this constraint Triggers should be used.

Page 11: Dbms Questions

65.How write a SQL statement to query the result set and display row as columns and columns as row?

Answer: TRANSFORM Count (Roll_no) AS Count of Roll_no

SELECT Academic_Status

FROM tbl_enr_status

GROUP BY Academic_Status

PIVOT Curnt_status;

66.Cursor Syntax brief history

Answer: To retrieve data with SQL one row at a time you need to use cursor processing. Not all relational databases support this, but many do. Here I show this in Oracle with PL/SQL, which is Procedural Language SQL .Cursor processing is done in several steps:1. Define the rows you want to retrieve. This is called declaring the cursor.2. Open the cursor. This activates the cursor and loads the data. Note that declaring the cursor doesn't load data, opening the cursor does.3. Fetch the data into variables.4. Close the cursor.

67.What is the data type of the surrogate key?

Answer: Data type of the surrogate key is either integer or numeric or number

68.How to write a sql statement to find the first occurrence of a non zero value?

Answer: There is a slight chance the column "a" has a value of 0 which is not null. In that case, you?ll loose the information. There is another way of searching the first not null value of a column:

select column_name from table_name where column_name is not null and rownum<2;

69. What is normalazation, types with e.g.\'s. _ with queries of all types

Answer: There are 5 normal forms. It is necessary for any database to be in the third normal form to maintain referential integrity and non-redundancy.

First Normal Form: Every field of a table (row, col) must contain an atomic value

Second Normal Form: All columns of a table must depend entirely on the primary key column.

Page 12: Dbms Questions

Third Normal Form: All columns of a table must depend on all columns of a composite primary key.

Fourth Normal Form: A table must not contain two or more independent multi-valued facts. This normal form is often avoided for maintenance reasons.

Fifth Normal Form: is about symmetric dependencies.

Each normal form assumes that the table is already in the earlier normal form.

70.Given an unnormalized table with columns:

Answer: The query will be: delete from tabname where rowid not in (select max (rowid) from tabname group by name) Here tabname is the table name.

71.How to find second maximum value from a table?

Answer: select max (field1) from tname1 where field1= (select max (field1) from tname1 where field1<(select max(field1) from tname1);

Field1- Salary field

Tname= Table name.

72. What is the advantage of specifying WITH GRANT OPTION in the GRANT command?

Answer: The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user.

73.What is the main difference between the IN and EXISTS clause in sub queries??

Answer: The main difference between the IN and EXISTS predicate in sub query is the way in which the query gets executed.

IN -- The inner query is executed first and the list of values obtained as its result is used by the outer query. The inner query is executed for only once.

EXISTS -- The first row from the outer query is selected, then the inner query is executed and, the outer query output uses this result for checking. This process of inner query execution repeats as many no .of times as there are outer query rows. That is, if there are ten rows that can result from outer query, the inner query is executed that many no. of times.

Page 13: Dbms Questions

74.TRUNCATE TABLE EMP; Will the outputs of the above two commands differ DELETE FROM EMP;

Answer: The difference is that the TRUNCATE call cannot be rolled back and all memory space for that table is released back to the server. TRUNCATE is much faster than DELETE and in both cases only the table data is removed, not the table structure.

75.What is table space?

Answer: Table-space is a physical concept. It has pages where the records of the database are stored with a logical perception of tables. So table space contains tables.

76. How to find out the 10th highest salary in SQL query?

Answer: Table - Tbl_Test_Salary

Column - int_salary

select max (int_salary)

from Tbl_Test_Salary

where int_salary in

(select top 10 int_Salary from Tbl_Test_Salary order by int_salary)

77.Which command executes the contents of a specified file?

Answer: START <filename> or @<filename>.

78.What is the difference between SQL and SQL SERVER?

Answer: SQL Server is an RDBMS just like oracle, DB2 from Microsoft

whereas

Structured Query Language (SQL), pronounced "sequel", is a language that provides an interface to relational database systems. It was developed by IBM in the 1970s for use in System R. SQL is a de facto standard, as well as an ISO and ANSI standard. SQL is used to perform various operations on RDBMS.

79.What is the difference between Single row sub-Query and Scalar Sub-Query?

Page 14: Dbms Questions

Answer: SINGLE ROW SUBQUERY RETURNS A VALUE WHICH IS USED BY WHERE CLAUSE, WHEREAS SCALAR SUBQUERY IS A SELECT STATEMENT USED IN COLUMN LIST CAN BE THOUGHT OF AS AN INLINE FUNCTION IN SELECT COLUMN LIST.

80. What does the following query do?

Answer: SELECT SAL + NVL (COMM, 0) FROM EMP;

It gives the added value of sal and comm for each employee in the emp table.

NVL (null value) replaces null with 0.

81.How to find second maximum value from a table?

Answer: select max (field1) from tname1 where field1= (select max (field1) from tname1 where field1< (select max (field1) from tname1);

Field1- Salary field

Tname= Table name.

82.I have a table with duplicate names in it. Write me a query which returns only duplicate rows with number of times they are repeated.

Answer: SELECT COL1 FROM TAB1

WHERE COL1 IN

(SELECT MAX (COL1) FROM TAB1

GROUP BY COL1

HAVING COUNT (COL1) > 1)

83.How to find out the database name from SQL*PLUS command prompt?

Answer: Select * from global_name;

This will give the data base name which u r currently connected to.....

84.How to display duplicate rows in a table?

Answer: select * from emp

group by (empid)

having count (empid)>1

Page 15: Dbms Questions

85.What is the value of comm and sal after executing the following query if the initial value of ?sal? is 10000

UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;

Answer : sal = 11000, comm = 1000.

86.1) What is difference between Oracle and MS Access?

2) What are disadvantages in Oracle and MS Access?

2) What are features & advantages in Oracle and MS Access?

Answer: Oracle's features for distributed transactions, materialized views and replication are not available with MS Access. These features enable Oracle to efficiently store data for multinational companies across the globe. Also these features increase scalability of applications based on Oracle.

87.What is the difference between oracle,sql and sql server ?

* Oracle is based on RDBMS.

* SQL is Structured Query Language.

* SQL Server is another tool for RDBMS provided by MicroSoft.

88.Difference between Store Procedure and Trigger?

* we can call stored procedure explicitly.

* but trigger is automatically invoked when the action defined in trigger is done.

ex: create trigger after Insert on

* this trigger invoked after we insert something on that table.

* Stored procedure can't be inactive but trigger can be Inactive.

* Triggers are used to initiate a particular activity after fulfilling certain condition.It need to define and can be enable and disable according to need.

89.What the difference between UNION and UNIONALL?

Union will remove the duplicate rows from the result set while Union all does'nt.

Page 16: Dbms Questions

90.What is the difference between TRUNCATE and DELETE commands?

Both will result in deleting all the rows in the table .TRUNCATE call cannot be rolled back as it is a DDL command and all memory space for that table is released back to the server. TRUNCATE is much faster.Whereas DELETE call is an DML command and can be rolled back.

91.Which system table contains information on constraints on all the tables created ?

yes,

USER_CONSTRAINTS,

system table contains information on constraints on all the tables created

92.Explain normalization ?

Normalisation means refining the redundancy and maintain stablisation. there are four types of normalisation :

first normal forms, second normal forms, third normal forms and fourth Normal forms.

93.How to find out the database name from SQL*PLUS command prompt?

Select * from global_name;

This will give the datbase name which u r currently connected to.....

94.What is the difference between SQL and SQL Server ?

SQLServer is an RDBMS just like oracle,DB2 from Microsoft

whereas

Structured Query Language (SQL), pronounced "sequel", is a language that provides an interface to relational database systems. It was developed by IBM in the 1970s for use in System R. SQL is a de facto standard, as well as an ISO and ANSI standard. SQL is used to perform various operations on RDBMS.

95.What is diffrence between Co-related sub query and nested sub query?

Correlated subquery runs once for each row selected by the outer query. It contains a reference to a value from the row selected by the outer query.

Page 17: Dbms Questions

Nested subquery runs only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.

For example,

Correlated Subquery:

select e1.empname, e1.basicsal, e1.deptno from emp e1 where e1.basicsal = (select max(basicsal) from emp e2 where e2.deptno = e1.deptno)

Nested Subquery:

select empname, basicsal, deptno from emp where (deptno, basicsal) in (select deptno, max(basicsal) from emp group by deptno)

96.WHAT OPERATOR PERFORMS PATTERN MATCHING?

Pattern matching operator is LIKE and it has to used with two attributes

1. % and

2. _ ( underscore )

% means matches zero or more characters and under score means mathing exactly one character

97.What is cluster.cluster index and non cluster index ?

Clustered Index:- A Clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table may have only one clustered index.Non-Clustered Index:- A Non-Clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows in the disk. The leaf nodes of a non-clustered index does not consists of the data pages. instead the leaf node contains index rows.

98.How can i hide a particular table name of our schema?

you can hide the table name by creating synonyms.

e.g) you can create a synonym y for table x

create synonym y for x;

99.What are the advantages and disadvantages of primary key and foreign key in SQL?Primary key

Page 18: Dbms Questions

Advantages

1) It is a unique key on which all the other candidate keys are functionally dependent

Disadvantage

1) There can be more than one keys on which all the other attributes are dependent on.

Foreign Key

Advantage

1)It allows refrencing another table using the primary key for the other table

100.Which date function is used to find the difference between two dates?

Datediff

for Eg: select datediff (dd,'2-06-2007','7-06-2007')

output is 5