0% found this document useful (0 votes)
71 views

SQL Interview Questions (25-50)

An outer join includes rows from tables when there are no matching values. A subselect works with another select, while a nested select passes the inner select results to the where clause of the outer select. Group by controls row presentation and order by controls column presentation. Common SQL functions include AVG, SUM, MIN, MAX, COUNT, and DISTINCT.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

SQL Interview Questions (25-50)

An outer join includes rows from tables when there are no matching values. A subselect works with another select, while a nested select passes the inner select results to the where clause of the outer select. Group by controls row presentation and order by controls column presentation. Common SQL functions include AVG, SUM, MIN, MAX, COUNT, and DISTINCT.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL Interview Questions (25-50)

Explain an outer join? An outer join includes rows from tables when there are no matching values in the tables. What is a subselect? Is it different from a nested select? A subselect is a select which works in conjunction with another select. A nested select is a kind of subselect where the inner select passes to the where criteria for the outer select. What is the difference between group by and order by? Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the 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? SUBSTR is used for string manipulation with column name, first position and string length used as arguments. E.g. SUBSTR (NAME, 1 3) refers to the first three characters in the column NAME. Explain the EXPLAIN statement? The explain statement provides information about the optimizer's choice of access path of the SQL. What is referential integrity? Referential integrity refers to the consistency that must be maintained between primary and foreign keys, i.e. every foreign key value must have a corresponding primary key value.

What is a NULL value? What are the pros and cons of using NULLS? A NULL value takes up one byte of storage and indicates that a value is not present as opposed to a space or zero value. It's the DB2 equivalent of TBD on an organizational chart and often correctly portrays a business situation. Unfortunately, it requires extra coding for an application program to handle this situation. What is a synonym? How is it used? A synonym is used to reference a table or view by another name. The other name can then be written in the application code pointing to test tables in the development stage and to production entities when the code is migrated. The synonym is linked to the AUTHID that created it.

What is an alias and how does it differ from a synonym? An alias is an alternative to a synonym, designed for a distributed environment to avoid having to use the location 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 select. 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). NUMERIC B). CHARACTER C). DATE AND TIME D). BLOBS E. BIT 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) TRUE B. FALSE C. UNKNOWN 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).

You might also like