Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1


Ratings: (0)|Views: 25|Likes:
Published by satishms10

More info:

Published by: satishms10 on Aug 27, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Interview Questions: Database
1. Question: What are the Difference between Functions and Procedures?
Answer: 1. Functions are used for computations where as Procedures can be used forperforming business logic2. Functions MUST return a value, Procedures need not be.3) You can have DML(insert, update, delete) statements in a Function. But, you cannot callsuch a function in a SQL query..eg: suppose, if u have a function that is updating a table.. you can~t call that function inany sql query.- select myFunction(field) from sometable;will throw error.4) function parameters are always IN, no OUT is possible5) function returns 1 value only. procedure can return multiple values(max. 1024)6) we can select the fields from function. in the case of procdure we cannot select the fields.7) Function do not return the images,text whereas stored procedures returns all
2. Question: What is the difference between UNION and UNION ALL ?
Answer: UNION ALL selects all records between two queries including duplicates, whereasUNION takes the time to sort records in order to remove duplicates. In short UNION onlyselects distinct values, UNION ALL selects all values.e.g.SELECT Date FROM table1 UNION SELECT Date FROM table2SELECT Date FROM table1 UNION ALL SELECT Date FROM table2
3. Question: What is a join and explain different types of joins.
Answer: Joins are used in queries to explain how different tables are related. Joins also let youselect data from a table depending upon data from another table.Types of joins: INNER JOIN, OUTER JOIN, CROSS JOIN.OUTER JOIN is further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTERJOINS.Table details
Interview Questions: Database
Cross Join
- A cross join merges two tables on every record in a geometric fashion, everyrecord of one table is combined with every record from the other table. Two tables of 10records each in a cross join will create a table of 100 (10 X 10) records.
Inner Join
- An Inner join is used to match two tables based on values of a common field.An inner join gets data from both tables where the specified data exists in both tables. For E.g.List of students in the database that were absent on December 4, 2003, you would use aninner join between the two tables "Student" and "Attendance"SELECT Student.ID, Student.FirstName, Student.LastName, Attendance.AttendanceCode,Attendance.MinutesAbsent FROM Student INNER JOIN Attendance ONStudent.ID=Attendance.ID WHERE Attendance.AttendanceDate=’12/4/2003’ 
Outer Join
- An outer join gets data from the source table at all times, and returns data fromthe outer joined table ONLY if it matches the criteria. When using outer joins, fields will be setto NULL if data does not exist in the outer-joined table. For E.g.SELECT Student.ID, Student.FirstName, Student.LastName, Attendance.AttendanceCode,Attendance.MinutesAbsent FROM Student INNER JOIN StudentSchedule ONStudentSchedule.ID=Student.ID< br /> LEFT OUTER JOIN Attendance ONStudent.ID=Attendance.ID AND Attendance.AttendanceDate=’12/4/2003’ WHEREStudentSchedule.Course=’E NGLISH 9’ 
a)Left Outer join
- All outer joins retrieve records from both tables, just as an inner joindoes. However, an outer join retrieves all of the records from one of the tables. A column inthe result is NULL if the corresponding input table did not contain a matching record.
b)Right Outer join
- The right outer join is similar to the left outer join in that it retrieves allthe records from one side of the relationship, but this time it’s the right table. Only recordswhere the condition values match are retrieved from the left.
c)Full Outer Join
- The full outer join retrieves all records from both the left and the righttable.
4. Question: For ~n~ number of SQL SELECT statements connected by UNION, howmany times should we specify UNION to eliminate the duplicate rows?
Answer: Only Once
5. Question: In the WHERE clause what is BETWEEN and IN?
Answer: IN keyword helps to limit the selection criteria to one or more discrete values, theBETWEEN keyword allows for selecting a range. The syntax for the BETWEEN clause is asfollows:SELECT "column_name" FROM "table_name" WHERE "column_name" BETWEEN ~value1~AND ~value2~This will select all rows whose column has a value between ~value1~ and ~value2~.The syntax for using the IN keyword is as follows:SELECT "column_name"FROM "table_name"WHERE "column_name" IN (~value1~, ~value2~, ...)The number of values in the parenthesis can be one or more, with each values separated bycomma. Values can be numerical or characters. If there is only one value inside the
Interview Questions: Database
parenthesis, this commend is equivalent toWHERE "column_name" = ~value1~
6. Question: What is ~LIKE~ used for in WHERE clause? What are the wildcardcharacters?
Answer: LIKE is another keyword that is used in the WHERE clause. Basically, LIKE allows youto do a search based on a pattern rather than specifying exactly what is desired (as in IN) orspell out a range (as in BETWEEN).The syntax for is as follows:SELECT "column_name" FROM "table_name" WHERE "column_name" LIKE {PATTERN} ‘%’ ( for a string of any character ) and ‘_’ (for any single character ) are the two wild cardcharacters.
7. Question: When do you use a LIKE statement?
Answer: To do partial search e.g. to search employee by name, you need not specifythe complete name; using LIKE, you can search for partial string matches.Example SQL : SELECT EMPNO FROM EMP WHERE EMPNAME LIKE ~RAMESH%~% is used to represent remaining all characters in the name.This query fetches all records contains RAMESH in six characters.
8. Question: What is a transaction?
Answer: A transaction is a logicl unit of work where all steps must be commited or rolled back.
9. Question: What is ACID?
Answer: ACID stands for Atomicity, Consistency, Isolation and Duralbility. These are theproperties of atransaction.1. Atomicity - states that database modifications must follow an "all or nothing" rule. Eachtransaction is said to be "atomic." If one part of the transaction fails, the entire transactionfails. It is critical that the database management system maintain the atomic nature of transactions in spite of any DBMS, operating system or hardware failure.2. Consistency - states that only valid data will be written to the database. If, for some reason,a transaction is executed that violates the database’s consistency rules, the entire transactionwill be rolled back and the database will be restored to a state consistent with those rules. Onthe other hand, if a transaction successfully executes, it will take the database from one statethat is consistent with the rules to another state that is also consistentwith the rules.3. Isolation - requires that multiple transactions occurring at the same time not impact eachother~s execution.For example, if Joe issues a transaction against a database at the same time that Mary issuesa different transaction, both transactions should operate on the database in an isolatedmanner. The database should either perform Joe~s entire transaction before executing Mary~sor vice-versa. This prevents Joe~s transaction from reading intermediate dataproduced as a side effect of part of Mary’s transaction that will not eventually be committed to

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->