SQL Server 2005 -Interview Questions for Biginners

• If I want to see what fields a table is made of, and what the sizes of the
fields are, what option  do I have to look for?
• What is a query?
• A SQL query is typed in the _________ .
• What is the purpose of the model database?
• What is the purpose of the master database?
• What is the purpose of the tempdb database?
• What is the purpose of the USE command?
• If you delete a table in the database, will the data in the table be deleted too?
• What is the Parse Query button used for? How does this help you?
• Tables are created in a ____________________ in SQL Server 2005.
• What is usually the first word in a SQL query?
• Does a SQL Server 2005 SELECT statement require a FROM?
• Can a SELECT statement in SQL Server 2005 be used to make an assignment?
Explain with examples.
• What is the ORDER BY used for?
• Does ORDER BY actually change the order of the data in the tables or does it just
change the output?
• What is the default order of an ORDER BY clause?
• What kind of comparison operators can be used in a WHERE clause?
• What are four major operators that can be used to combine conditions on a WHERE
clause? Explain the operators with examples.
• What are the logical operators?
• In a WHERE clause, do you need to enclose a text column in quotes? Do you need to
enclose a numeric column in quotes?
• Is a null value equal to anything? Can a space in a column be considered a null
value? Why or why not?
• Will COUNT(column) include columns with null values in its count?
• What are column aliases? Why would you want to use column aliases? How can you
embed blanks in column aliases?
• What are table aliases?
• What are table qualifiers? When should table qualifiers be used?
• Are semicolons required at the end of SQL statements in SQL Server 2005?
• Do comments need to go in a special place in SQL Server 2005?
• When would you use the ROWCOUNT function versus using the WHERE clause?
• Is SQL case-sensitive? Is SQL Server 2005 case-sensitive?
• What is a synonym? Why would you want to create a synonym?
• Can a synonym name of a table be used instead of a table name in a SELECT
statement?
• Can a synonym of a table be used when you are trying to alter the definition
of a table?
• Can you type more than one query in the query editor screen at the same time?
• The INSERT INTO .. VALUES option will insert rows into the _________ of a table.
• While you are inserting values into a table with the INSERT INTO .. VALUES
option, does the order of the columns in the INSERT statement have to be the
same as the order of the columns in the table?
• While you are inserting values into a table with the INSERT INTO .. SELECT
option, does the  order of the columns in the INSERT statement have to be
the same as the order of the columns in the table?
• When would you use an INSERT INTO .. SELECT option versus an INSERT INTO .. VALUES   option? Give an example of each.
• What does the UPDATE command do?
• Can you change the data type of a column in a table after the table has been
created? If so,which command would you use?
• Will SQL Server 2005 allow you to reduce the size of a column?
• What integer data types are available in SQL Server 2005?
• What is the default value of an integer data type in SQL Server 2005?
• What decimal data types are available in SQL Server 2005?
• What is the difference between a CHAR and a VARCHAR datatype?
• Does Server SQL treat CHAR as a variable-length or fixed-length column?
Do other SQL implementations treat it in the same way?
• If you are going to have too many nulls in a column, what would be the best
data type to use?
• When columns are added to existing tables, what do they initially contain?
• What command would you use to add a column to a table in SQL Server?
• In SQL Server, which data type is used to store large object data types?
• If I do not need to store decimal places, what would be a good numeric data
type to use?
• I I need to store decimal places, but am not worried about rounding errors,
what would be a    good  data type to use?
• Should a column be defined as a FLOAT if it is going to be used as a primary key?
• What is a join? Why do you need a join?
• What is an INNER JOIN?
• Which clause[s] can be used in place of the JOIN in Server SQL?
• What is the Cartesian product?
• What would be the Cartesian product of a table with 15 rows and another table
with 23 rows?
• List some uses of the Cartesian product.
• What is an equi-join?
• What is a non-equi-join? Give an example of an non-equi-join.
• What is a self join? Give an example of a self join.
• What is a LEFT OUTER JOIN?
• What is a RIGHT OUTER JOIN?
• What is a CROSS JOIN?
• What is a FULL OUTER JOIN?


• Does Server SQL allow the use of *= to perform outer joins?
• What is the maximum number of rows that a self join can produce?
• For what kinds of joins will the associative property hold?
• What would be the Cartesian product of the two sets {a,b,c} and {c,d,e}?
• What are functions?
• What are aggregate functions? Give examples of aggregate functions.
What is another term for   an aggregate function?
• What are row-level functions? Give examples of row-level functions.
• Is COUNT an aggregate function or a row-level function? Explain why.
Give at least one   example of when the COUNT function may come in handy.
Does the COUNT function take nulls into account?
• Is AVG an aggregate function or a row-level function?
• What is the NULLIF function? Explain.
• How are ties handled in SQL Server?
• How does the DISTINCT function work?
• Are string functions (for example, SUBSTRING, RIGHT, LTRIM) aggregate
functions or row- level functions?
• What is the SUBSTRING function used for?
• What is the CHARINDEX function used for?
• What function would you use to find the leftmost characters in a string?
• What are the LTRIM/RTRIM functions used for?
• What function would produce the output in all lowercase?
• What function would you use to find the length of a string?
• What characters or symbols are most commonly used as wildcard characters in
SQL Server 2005?
• What is the concatenation operator in Server SQL 2005?
• What does the YEAR function do?
• What does the MONTH function do?
• What does the GEtdATE function do?
• What will the following query produce in SQL Server 2005?
o SELECT ('.....'+ names) AS [names]
o FROM Employee

• Does Server SQL allow an expression like COUNT(DISTINCT column_name)?
• How is the ISNULL function different from the NULLIF function?
• What function would you use to round a value to three decimal places?
• Which functions can the WITH TIES option be used with?
• What clause does the WITH TIES option require?
• What is the default date format in SQL Server 2005?
• How do dates have to be entered in Server SQL 2005?
• What function is used to convert between data types?
• What function is useful for formatting numbers?
• What function is useful for formatting dates?
• Which has precedence, AND or OR?
• Why do we need derived structures?
• What is a view?
• List some advantages of using views.
• List some advantages of using temporary tables.
• Can temporary tables replace views in all cases?
• What is the difference between a view and temporary table?
• What is the difference between a local temporary table and global temporary table?
• If data is changed in a view, is it changed in the original table?
• If data is changed in a temporary table, does it automatically change data in
the original table?
• What happens to local temporary tables after the session has been ended?
• What happens to global temporary table after the session has been ended?
• Which type of temporary table has a system-generated suffix attached to it?
What does this    suffix mean?
• Why are inline views helpful?
• In SQL Server, is the ORDER BY clause allowed during the creation of a view?
• Is SELECT INTO allowed in a view? Why or why not?
• Where is the data stored in a view?
• How do you delete views?
• How do you delete a temporary table?
• Do you need to delete a local temporary table? Why or why not?
• Which operators have the highest/lowest precedence?
• In SQL Server, if a column of FLOAT data type were divided by a column of REAL
data type,what data type would the resulting column have? (Hint: refer to the
section on Data Type    Preference.)
• Is an ORDER BY clause necessary when you use a DISTINCT? Why or why not?
• What are the major differences between the UNION operation and the JOIN operation?
• What is the major difference between the UNION and the UNION ALL?
• What major set operator does SQL Server 2005 not have? How can these problems
be resolved?
• What does union compatibility mean?
• What data types are union-compatible?
• What is the maximum number of rows that can result from a UNION of two tablesone
with 5 rows and the other with 6 rows?
• How can a UNION be used to implement an outer join? Explain.
• Does SQL Server 2005 support the MINUS operation? How can this be resolved? Give    examples.
• What is a full outer join? Does SQL Server 2005 directly support a full outer join?
• Do you need the same number of columns to perform a union?
• Do you need the same data types to perform a union?
• Do you need the same number of columns to perform a join?
• From the examples given in the chapter, what does the UNION JOIN appear to do?
• If a VARCHAR column were unioned with a CHAR column, what would the resulting
column be?
• What does set compatibility mean?
• What is the maximum number of rows that can result from a INTERSECT of two
tablesone with 5 rows and the other with 6 rows?
• Do you need the same number of columns to perform an INTERSECT operation?
• Do you need the same data types to perform an INTERSECT operation?
• What is a subquery?
• Which part of the query/subquery is considered the inner query, and which part
is considered the  outer query?
• Can a subquery always be done as a join? Why or why not?
• When writing a query that will have a subquery, how do you determine which
table/tables will go in the outer query?
• Which predicate can usually be reformulated into a join?
• When using operators, are many values acceptable from a result of a subquery?
• What can you do to insure a working subquery?
• What do aggregate functions do?
• How does the GROUP BY clause work?
• What is the difference between a GROUP BY and ORDER BY?
• What is the HAVING clause used for?
• Can the WHERE clause always be considered a substitute for the HAVING clause? Why or why    not?
• Do functions of functions have to be handled in a special way in Server SQL 2005?
• Will nulls in grouped columns be included in a result set?
• How do aggregate functions treat nulls?
• Does the sequence of the columns in a GROUP BY clause have an effect on the end result?
• When would it not make sense to use the GROUP BY and DISTINCT functions together?
• Is GROUP BY affected by nulls?
• Which comes first in a SELECT statement, an ORDER BY or GROUP BY? Why?
• The GROUP BY and ________________ clauses are used together.
• What is a noncorrelated subquery?
• Which type of subquery can be executed on its own?
• Which part of a query is evaluated first, the query or the subquery?
• What are correlated subqueries?
• What does the EXISTS predicate do?
• What are considered universal qualifiers?
• Is correlation necessary when we use EXISTS? Why?
• Explain how the "for all" type SQL query involves a double-nested correlated subquery using    the NOT EXISTS predicate.
• What is an index?
• Does an index slow down updates on indexed columns?
• What is a constraint?
• How many indexes does SQL Server 2005 allow you to have on a table?
• What command would you use to create an index?
• Is there a difference between an index and a constraint?
• What is the default ordering that will be created by an index (ascending or descending)?
• When can the UNIQUE option be used?
• What does the IGNORE NULL option do?
• How do you delete an index?
• What does the NOT NULL constraint do?
• What command must you use to include the NOT NULL constraint after a table has already    been created?
• When a PRIMARY KEY constraint is included in a table, what other constraints does this    imply?
• What is a concatenated primary key?
• How are the UNIQUE and PRIMARY KEY constraints different?
• What is a referential integrity constraint? What two keys does the referential integrity     constraint usually include?
• What is a foreign key?
• What does the ON DELETE CASCADE option do?
• What does the ON UPDATE NO ACTION do?
• Can you use the ON DELETE and ON UPDATE in the same constraint?

Oracle Interview Questions and Answers : SQL

 
1. To see current user name
    Sql> show user;

2. Change SQL prompt name
     SQL> set sqlprompt “Manimara > “
     Manimara >
     Manimara >

3. Switch to DOS prompt
     SQL> host

4. How do I eliminate the duplicate rows ?
     SQL> delete from table_name where rowid not in (select max(rowid)
     from  table group by  duplicate_values_field_name);
     or
     SQL> delete duplicate_values_field_name dv from table_name ta where
                rowid <(select min(rowid) from table_name tb where ta.dv=tb.dv);  

----->Get answers to all your Questions at--->WebDeveloper's Corner<-----

13. Display the number value in Words                          
         SQL> select sal, (to_char(to_date(sal,'j'), 'jsp')) from emp;

14. Display Odd/ Even number of records      
      Odd number of records:     
      select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);      
      1      
      3      
      5     
     Even number of records:     
    select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp)      
      2      
      4     
      6

15. Which date function returns number value?        
     months_between

16. Any three PL/SQL Exceptions?       
     Too_many_rows, No_Data_Found, Value_Error, Zero_Error, Others

17. What are PL/SQL Cursor Exceptions?       
     Cursor_Already_Open, Invalid_Cursor

18. Other way to replace query result null value with a text       
       SQL> Set NULL ‘N/A’     to reset SQL> Set NULL ‘’

19. What are the more common pseudo-columns?
      SYSDATE, USER , UID, CURVAL, NEXTVAL, ROWID, ROWNUM

20. What is the output of SIGN function?
      1 for positive value, 0 for Zero, -1 for Negative value.

21. What is the maximum number of triggers, can apply to a single table?
       12 triggers.

21. How would you determine the time zone under which a database was operating?
       select DBTIMEZONE from dual;

22. Explain the use of setting GLOBAL_NAMES equal to TRUE.
       Setting GLOBAL_NAMES dictates how you might connect to a database. This
       variable is either TRUE or FALSE and if it is set to TRUE it enforces database
       links to have the same name as the remote database to which they are linking.

23. What command would you use to encrypt a PL/SQL application?
       WRAP

24. Explain the difference between a FUNCTION, PROCEDURE and PACKAGE.
       A function and procedure are the same in that they are intended to be a
      collection of PL/SQL code that carries a single task. While a procedure does
      not have to return any values to the calling application, a function will return
      a single value. A package on the other hand is a collection of functions and
      procedures that are grouped together based on their commonality to a
      business function or application.

25. Explain the use of table functions.
      Table functions are designed to return a set of rows through PL/SQL logic
      but are intended to be used as a normal table or view in a SQL statement.
      They are also used to pipeline information in an ETL process.

26. Name three advisory statistics you can collect.
       Buffer Cache Advice, Segment Level Statistics, & Timed Statistics

27. Where in the Oracle directory tree structure are audit traces placed?
       In unix $ORACLE_HOME/rdbms/audit, in Windows the event viewer

28. Explain materialized views and how they are used.
       Materialized views are objects that are reduced sets of information that
       have been summarized, grouped, or aggregated from base tables. They
       are typically used in data warehouse or decision support systems.

29. When a user process fails, what background process cleans up after it?
       PMON

30. What background process refreshes materialized views?
       The Job Queue Processes.

31. How would you determine what sessions are connected and what resources they
      are waiting for?
      Use of V$SESSION and V$SESSION_WAIT

32. Describe what redo logs are.
       Redo logs are logical and physical structures that are designed to hold all
       the changes made to a database and are intended to aid in the recovery
       of a database.

33. How would you force a log switch?
       ALTER SYSTEM SWITCH LOGFILE;

34. Give two methods you could use to determine what DDL changes have been made.
      You could use Logminer or Streams

35. What does coalescing a tablespace do?
      Coalescing is only valid for dictionary-managed tablespaces and
      de-fragments space  by combining neighboring free extents into large
      single extents.

36. What is the difference between a TEMPORARY tablespace and a PERMANENT
      tablespace?
      A temporary tablespace is used for temporary objects such as sort
     structures while permanent tablespaces are used to store those
     objects meant to be used as the true  objects of the database.

37. Name a tablespace automatically created when you create a database.
       The SYSTEM tablespace.

38. When creating a user, what permissions must you grant to allow them
       to connect to the database?
      Grant the CONNECT to the user.

39. How do you add a data file to a tablespace?
        ALTER TABLESPACE ADD
           DATAFILE SIZE

40. How do you resize a data file?
       ALTER DATABASE DATAFILE RESIZE ;

41. What view would you use to look at the size of a data file?
       DBA_DATA_FILES

42. What view would you use to determine free space in a tablespace?
       DBA_FREE_SPACE

43. How would you determine who has added a row to a table?
       Turn on fine grain auditing for the table.

44. How can you rebuild an index?
       ALTER INDEX REBUILD;

45. Explain what partitioning is and what its benefit is.
      Partitioning is a method of taking large tables and indexes and splitting them into
      smaller, more manageable pieces.

46. You have just compiled a PL/SQL package but got errors, how would you view
       the errors?
       SHOW ERRORS

47. How can you gather statistics on a table?
       The ANALYZE command.

48. How can you enable a trace for a session?
       Use the DBMS_SESSION.SET_SQL_TRACE or
       Use ALTER SESSION SET SQL_TRACE = TRUE;

49. What is the difference between the SQL*Loader and IMPORT utilities?
       These two Oracle utilities are used for loading data into the database.
       The difference  is that the import utility relies on the data being
       produced by another Oracle utility EXPORT while the SQL*Loader
       utility allows data to be loaded that has been produced  by other
       utilities from different data sources just so long as it conforms to ASCII
       formatted or delimited files.

50. Name two files used for network connection to a database.
      TNSNAMES.ORA and SQLNET.ORA