Wednesday, May 4, 2011

Few SQL Interview Question Answers

Replication :

Replication is the process of copying and distributing data and database objects from one database to another and then synchronizing between databases for consistency.

Transactional Replication
Merge Replication
Snapshot Replication

Snowflake Schema :

A snowflake schema is a logical arrangement of tables in a multidimensional database

Correlated SubQuery :

A correlated subquery is a subquery where the inner query is evaluated once for every value returned by the outer query.

SELECT O.OrderID, O.OrderDate,
(SELECT MAX (Od.UnitPrice) FROM [Order Details] AS Od
WHERE Od.OrderID = O.orderid) AS MaxUnitPrice
FROM Orders AS O

Having and Where :

HAVING specifies a search condition for a group or an aggregate function used in SELECT statement.

HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.

A HAVING clause is like a WHERE clause, but applies only to groups as a whole, whereas the WHERE clause applies to individual rows.

Difference Between Union vs. Union All

A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records
returned are unique from your union, use UNION ALL instead, it gives faster results.

SQL - Wildcard Operators :

The percent sign represents zero, one, or multiple characters. The underscore represents a single number or character. The symbols can be used in combinations.


How do you sort in SQL?

The ORDER BY keyword is used to sort the result-set by a specified column.

Explain the difference between optimistic and pessimistic locking.

In optimistic locking the row will not be locked until the actual update is performed. In order to prevent the lost update issue a version number column will be used.

In pessimistic locking the row will be locked at the time when the data is selected from the database. This will prevent other users who want to update the same record. This should not prevent the readers but this behaviour varies from database to database.

Tuesday, May 3, 2011

Engineer rocks !

Selecting a software bridegroom..

Priya: hey! what is the matter you have called up all of a sudden?

Ramya: do u remember that my parents gave my horoscope, to search for a suitable match, to many people? So many horoscopes of the groom has come.. in that 4-5 seems to match.. I don't know which one to select, I am confused because of it.

Priya: what is the confusion about?

Ramya: horoscopes of many software engineers have come. That's why I don't know whom I must select among this. You are a software engineer na pls give me some suggestion .

Priya: not a problem at all. So tell me the position that each one holds.

Ramya: first is a manager .

Priya: manager?? Then he will showcast himself that he is busy always. But he will not do anything properly. He will get u 1 kg of rice and ask you to prepare for the whole area say a village. He will get you mutton and ask you to prepare chicken 65. Even if you protest telling you can't make it, he'll not accept. He will tell you to work hard day and night to prepare it. He will also tell he'll provide you with the night cab. Even if you ask how can I prepare chicken 65 out of it by sitting day and night he will not accept.

Ramya: ohh..so dangerous he is!! Then I must escape. Next is a test engineer.

Priya: he is more dangerous than the other person. Whatever you do he will correctly tell only the fault in it. Even if you try to surprise him with 10 variety of food, he will tell the item which does not have salt in it. If you ask him "will you not at least tell that it is good", he will reply back saying it is your duty to make it good so why must I tell that. He is sooo good ...

Ramya: then a NO to him also. Next is the performance test engineer.

Priya: he is another specimen. even if everything is good, he will ask why did it take this much time. If you take 10 minutes to make a coffee, he will question you asking why you have taken 10 min for a coffee which
can be done within 5 min. Even if you say that he is talking about the instant coffee while you have made the filter coffee, he will not accept. The same will be with all the work you do. You must not think about this person if you want to do make up in your life !!!

Ramya: then! you mean to say that we should not marry software guys??

Priya: who said like that?? In software there is one more group. They are called the developers group. How much ever you hit them they will bear.

Ramya: then tell about them.

Priya: you don't have to do anything. They will do everything themselves. If we sit back and just boost them it is enough. But the problem with them is- they will say "I know it" whatever you ask them. Even that is ok. They will bear how much ever you hit them but the condition is you must keep saying "you are too good" after hitting them every time.

Ramya: this is superb. Then we must search for this kind of a groom...