SQL Interview Questions(25-50)

Explain an outer join?













inner select passes to the where criteria for the outer select.





What is the difference between group by and order by?





SELECT statement.





What keyword does an SQL SELECT statement use for a string search?


The LIKE keyword allows for string searches.  The % sign is used as a wildcard.





What are some SQL aggregates and other built-in functions?


The common aggregate, built-in functions are AVG, SUM, MIN, MAX, COUNT and DISTINCT.





How is the SUBSTR keyword used in SQL?










Explain the EXPLAIN statement?








What is referential integrity?





foreign key value must have a corresponding primary key value. 










value.  It's the DB2 equivalent of TBD on an organizational chart and often correctly portrays a business situation. 








What is a synonym?  How is it used?








The synonym is linked to the AUTHID that created it.












qualifier of a table or view.  The alias is not dropped when the table is dropped.





When can an insert of a new primary key value threaten referential integrity?


Never. New primary key values are not a problem.  However, the values of foreign key inserts must have



corresponding primary key values in their related tables. And updates of primary key values may require changes in



foreign key values to maintain referential integrity.





What is the difference between static and dynamic SQL?


Static SQL is hard-coded in a program when the programmer knows the statements to be executed.  For dynamic SQL



the program must dynamically allocate memory to receive the query results.




Compare a subselect to a join?


Any subselect can be rewritten as a join, but not vice versa. Joins are usually more efficient as join rows can be



returned immediately, subselects require a temporary work area for inner selects results while processing the outer








What is the difference between IN subselects and EXISTS subselect?


If there is an index on the attributes tested an IN is more efficient since DB2 uses the index for the IN.  (IN for index is



the mnemonic).





What is a Cartesian product?


A Cartesian product results from a faulty query.  It is a row in the results for every combination in the join tables.





What is a tuple?


A tuple is an instance of data within a relational database.





What is the difference between static and dynamic SQL?


Static SQL is compiled and optimized prior to its execution; dynamic is compiled and optimized during execution.







Any SQL implementation covers data types in couple of main categories. Which of the following are those data



types ? (Check all that apply)















A,B,C. Not all SQL implementations have a BLOB or a BIT data types.





We have a table with a CHARACTER data type field. We apply a ">" row comparison between this field and



another CHARACTER field in another table. What will be the results for records with field value of NULL?



(Check one that applies the best)












D. Error.



E. Those records will be ignored



C. NULL in a row when compared will give an UNKNOWN result.





Any database needs to go through a normalization process to make sure that data is represented only once. This



         will eliminate problems with creating or destroying data in the database. The normalization process is done



         usually in three steps which results in first, second and third normal forms. Which best describes the process to



         obtain the third normal form? (Check one that applies the best)



Each table should have related columns.  



Each separate table should have a primary key.  



We have a table with multi-valued key. All columns that are dependent on only one or on some of the keys should be moved in a different table.



If a table has columns not dependent on the primary keys, they need to be moved in a separate table.  



E. Primary key is always UNIQUE and NOT NULL.



D. All columns in a table should be dependent on the primary key. This will eliminate transitive dependencies in



which A depends on B, and B depends on C, but we're not sure how C depends on A.





SQL can be embedded in a host program that uses a relational database as a persistent data repository. Some of



the most important pre-defined structures for this mechanism are SQLDA ("SQL Descriptor Area") and



SQLCA ("SQL Communications Area") SQLCA contains two structures - SQLCODE and SQLSTATE.



SQLSTATE is a standard set of error messages and warnings in which the first two characters defines the class



and the last three defines the subclass of the error. Which of the following SQLSTATE codes is interpreted as



"No data returned"?(Check one that applies the best) 



A). 00xxx  



B). 01xxx 



C). 02xxx  



D). 22xxx  



E). 2Axxx



C. 00 - is successful completion, 01 - warnings, 22 - is data exception and 2A is syntax error. The SQLSTATE code



format returned for "No data returned" is "02xxx".





What are common SQL abend codes? (e.g. : 0,100 etc.,)



-818 time stamp mismatch



-180 wrong data moved into date field






What is meant by dynamic SQL?



Dynamic SQL are SQL statements that are prepared and executed within a program while the program is executing.



The SQL source is contained in host variables rather than being hard coded into the program. The SQL statement may



change from execution to execution.





What is meant by embedded SQL?



They are SQL statements that are embedded with in application program and are prepared during the program



 preparation process before the program is executed. After it is prepared, the statement itself does not change(although



values of host variables specified within the statement might change).



Related Links

Comments (35)

Said this on 10-11-2007 At 12:55 pm
itz a very nice nd interesting site for the upliftment of the youth nd thier needs
Said this on 8-7-2010 At 04:00 pm

Thease Question is good for readout but not fully satisfied .

Said this on 10-26-2007 At 10:16 am
Said this on 1-8-2010 At 06:01 pm

hi its nice

Said this on 4-20-2010 At 03:50 pm


Said this on 10-28-2007 At 08:21 pm
this is used to upgrade my knowledge of sql thank u.
Said this on 1-31-2010 At 07:38 am

hi vidyaa

Said this on 7-7-2008 At 10:30 am
I am not fully satisfied with ur these question.these are not safficient for us.
Said this on 3-11-2012 At 12:10 pm

thanx for the questions..but i think you should provide the basic commands of sql for new begineers..for basic commands you can visit http://studentluv.com/sql-questions/

Said this on 8-14-2008 At 02:40 pm
good questions..of great help...
Said this on 8-26-2008 At 11:24 pm
good question...thankyou
Said this on 9-11-2008 At 03:48 pm
Need Explanatory with Examples.
Said this on 12-14-2008 At 10:01 am
Said this on 12-20-2008 At 03:10 pm
no i donot know
Said this on 5-21-2009 At 04:11 pm
All are important questions..... Thanks for posting......
Said this on 5-22-2009 At 03:36 pm
most useful topics. continue giving more FAQ's
Said this on 6-5-2009 At 03:07 pm
it is very nice
arun bala
Said this on 8-5-2009 At 07:16 pm
simply superb
Said this on 12-11-2010 At 11:24 am

Yeah It Is

Shafali Kataria
Said this on 1-24-2010 At 11:15 am

These questions are very helpful but it is not sufficient set of questions to face an interview . PLaese put some more question related to the queries i. finding 3rd row in the table, having only those values which occurs more than once...........etc...

<!--Session data-->

Said this on 4-21-2010 At 01:01 pm

this questions are very good to upgrade our knowledge

Said this on 5-23-2010 At 07:30 pm

its very amazing for developer who know practical but week in theory..



Said this on 5-31-2010 At 12:13 pm


can you please increase the stuff..??

Ruby Gupta
Said this on 9-6-2010 At 10:40 am

Give more questions on SQl


Said this on 10-25-2010 At 04:25 pm

these questions are very helpfull for interviews


Said this on 12-11-2010 At 01:58 am


pname             packagename                    cost

MARY               README                             1200
ANAND             PARACHUTES                     6000
ANAND             VIDEO TITLING                   16000
JULIANA           INVENTORY                        3500
KAMALA           PAYROLL PKG                    20000
MARY                FINANCIAL ACCT             85000
MARY               CODE GENERATOR          20000
PATTRICK        README                            1200
QADIR               BOMBS AWAY                 3000
QADIR               VACCINES                      3100
RAMESH             HOTEL MGMT                35000
RAMESH               DEAD LEE                    4500
REMITHA              PC UTILITIES                5000
REMITHA               TSR HELP PKG             6000
REVATHI             HOSPITAL MGMT           75000
VIJAYA               TSR EDITOR                      7000


My Question is:-

Display each pname,costliest package name and cheapest package name developed by him or her...?

This query should run in sqlserver 2005...

Said this on 7-8-2011 At 11:09 pm

i dnt know whether its ryt or not


Select pname, packagename, max(cost), min(cost) from software group by pname, packagename order by pname;

Said this on 12-22-2010 At 12:52 am

to learn basic concept it's nice given ......



Said this on 1-24-2011 At 03:11 pm


Said this on 3-9-2011 At 04:04 pm

its nice answer, but points to extra explain and meaningful sentences.

Said this on 4-4-2011 At 05:14 pm


how to get the size of the database?

Said this on 8-25-2011 At 06:08 pm

The size of database depends on space occupied on  harddisk.Database mostly resides on server so, from server it is easily identify the size of database.

Said this on 5-20-2011 At 01:01 pm

give me complete information about question what he asked

Said this on 10-30-2011 At 05:11 pm

The question are simple in nature. Can you post some scenarios?

Said this on 2-11-2012 At 11:50 am

SQL...its can help for freshers seeing of questions going for interview it can increase the knowledge.............

Post a Comment
* Your Name:
* Your Email:
(not publicly displayed)
Reply Notification:
Approval Notification:
* Security Image:
Security Image Generate new
Copy the numbers and letters from the security image:
* Message:

Email to Friend


Email to Friend
* Your Name:
* Your Email:
* Friend's Name:
* Friend's Email:
* Security Image:
Security Image Generate new
Copy the numbers and letters from the security image
* Message: