Microsoft SQL Questions for Freshers : (1 to 10 parts included)

Part - 1

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.

Part - 2

  1. What is usually the first word in a SQL query?

  2. Does a SQL Server 2005 SELECT statement require a FROM?

  3. Can a SELECT statement in SQL Server 2005 be used to make an assignment? Explain with examples.

  4. What is the ORDER BY used for?

  5. Does ORDER BY actually change the order of the data in the tables or does it just change the output?

  6. What is the default order of an ORDER BY clause?

  7. What kind of comparison operators can be used in a WHERE clause?

  8. What are four major operators that can be used to combine conditions on a WHERE clause? Explain the operators with examples.

  9. What are the logical operators?

  10. In a WHERE clause, do you need to enclose a text column in quotes? Do you need to enclose a numeric column in quotes?

  11. Is a null value equal to anything? Can a space in a column be considered a null value? Why or why not?

  12. Will COUNT(column) include columns with null values in its count?

  13. What are column aliases? Why would you want to use column aliases? How can you embed blanks in column aliases?

  14. What are table aliases?

  15. What are table qualifiers? When should table qualifiers be used?

  16. Are semicolons required at the end of SQL statements in SQL Server 2005?

  17. Do comments need to go in a special place in SQL Server 2005?

  18. When would you use the ROWCOUNT function versus using the WHERE clause?

  19. Is SQL case-sensitive? Is SQL Server 2005 case-sensitive?

  20. What is a synonym? Why would you want to create a synonym?

  21. Can a synonym name of a table be used instead of a table name in a SELECT statement?

  22. Can a synonym of a table be used when you are trying to alter the definition of a table?

  23. Can you type more than one query in the query editor screen at the same time?

Part -3

  1. The INSERT INTO .. VALUES option will insert rows into the _________ of a table.

  2. 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?

  3. 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?

  4. When would you use an INSERT INTO .. SELECT option versus an INSERT INTO .. VALUES option? Give an example of each.

  5. What does the UPDATE command do?

  6. 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?

  7. Will SQL Server 2005 allow you to reduce the size of a column?

  8. What integer data types are available in SQL Server 2005?

  9. What is the default value of an integer data type in SQL Server 2005?

  10. What decimal data types are available in SQL Server 2005?

  11. What is the difference between a CHAR and a VARCHAR datatype?

  12. Does Server SQL treat CHAR as a variable-length or fixed-length column? Do other SQL implementations treat it in the same way?

  13. If you are going to have too many nulls in a column, what would be the best data type to use?

  14. When columns are added to existing tables, what do they initially contain?

  15. What command would you use to add a column to a table in SQL Server?

  16. In SQL Server, which data type is used to store large object data types?

  17. If I do not need to store decimal places, what would be a good numeric data type to use?

  18. If I need to store decimal places, but am not worried about rounding errors, what would be a good data type to use?

  19. Should a column be defined as a FLOAT if it is going to be used as a primary key?

Part - 4
  1. What is a join? Why do you need a join?

  2. What is an INNER JOIN?

  3. Which clause[s] can be used in place of the JOIN in Server SQL?

  4. What is the Cartesian product?

  5. What would be the Cartesian product of a table with 15 rows and another table with 23 rows?

  6. List some uses of the Cartesian product.

  7. What is an equi-join?

  8. What is a non-equi-join? Give an example of an non-equi-join.

  9. What is a self join? Give an example of a self join.

  10. What is a LEFT OUTER JOIN?

  11. What is a RIGHT OUTER JOIN?

  12. What is a CROSS JOIN?

  13. What is a FULL OUTER JOIN?

  14. Does Server SQL allow the use of *= to perform outer joins?

  15. What is the maximum number of rows that a self join can produce?

  16. For what kinds of joins will the associative property hold?

  17. What would be the Cartesian product of the two sets {a,b,c} and {c,d,e}?

Part - 5
  1. What are functions?

  2. What are aggregate functions? Give examples of aggregate functions. What is another term for an aggregate function?

  3. What are row-level functions? Give examples of row-level functions.

  4. 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?

  5. Is AVG an aggregate function or a row-level function?

  6. What is the NULLIF function? Explain.

  7. How are ties handled in SQL Server?

  8. How does the DISTINCT function work?

  9. Are string functions (for example, SUBSTRING, RIGHT, LTRIM) aggregate functions or row-level functions?

  10. What is the SUBSTRING function used for?

  11. What is the CHARINDEX function used for?

  12. What function would you use to find the leftmost characters in a string?

  13. What are the LTRIM/RTRIM functions used for?

  14. What function would produce the output in all lowercase?

  15. What function would you use to find the length of a string?

  16. What characters or symbols are most commonly used as wildcard characters in SQL Server 2005?

  17. What is the concatenation operator in Server SQL 2005?

  18. What does the YEAR function do?

  19. What does the MONTH function do?

  20. What does the GEtdATE function do?

  21. What will the following query produce in SQL Server 2005?

        SELECT ('.....'+ names) AS [names]
    FROM Employee

  22. Does Server SQL allow an expression like COUNT(DISTINCT column_name)?

  23. How is the ISNULL function different from the NULLIF function?

  24. What function would you use to round a value to three decimal places?

  25. Which functions can the WITH TIES option be used with?

  26. What clause does the WITH TIES option require?

  27. What is the default date format in SQL Server 2005?

  28. How do dates have to be entered in Server SQL 2005?

  29. What function is used to convert between data types?

  30. What function is useful for formatting numbers?

  31. What function is useful for formatting dates?

Part - 6

  1. Which has precedence, AND or OR?

  2. Why do we need derived structures?

  3. What is a view?

  4. List some advantages of using views.

  5. List some advantages of using temporary tables.

  6. Can temporary tables replace views in all cases?

  7. What is the difference between a view and temporary table?

  8. What is the difference between a local temporary table and global temporary table?

  9. If data is changed in a view, is it changed in the original table?

  10. If data is changed in a temporary table, does it automatically change data in the original table?

  11. What happens to local temporary tables after the session has been ended?

  12. What happens to global temporary table after the session has been ended?

  13. Which type of temporary table has a system-generated suffix attached to it? What does this suffix mean?

  14. Why are inline views helpful?

  15. In SQL Server, is the ORDER BY clause allowed during the creation of a view?

  16. Is SELECT INTO allowed in a view? Why or why not?

  17. Where is the data stored in a view?

  18. How do you delete views?

  19. How do you delete a temporary table?

  20. Do you need to delete a local temporary table? Why or why not?

  21. Which operators have the highest/lowest precedence?

  22. 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.)

  23. Is an ORDER BY clause necessary when you use a DISTINCT? Why or why not?

Part - 7
  1. What are the major differences between the UNION operation and the JOIN operation?

  2. What is the major difference between the UNION and the UNION ALL?

  3. What major set operator does SQL Server 2005 not have? How can these problems be resolved?

  4. What does union compatibility mean?

  5. What data types are union-compatible?

  6. 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?

  7. What is the maximum number of rows that can result from a JOIN of two tablesone with 5 rows and the other with 6 rows?

  8. How can a UNION be used to implement an outer join? Explain.

  9. Does SQL Server 2005 support the MINUS operation? How can this be resolved? Give examples.

  10. What is a full outer join? Does SQL Server 2005 directly support a full outer join?

  11. Do you need the same number of columns to perform a union?

  12. Do you need the same data types to perform a union?

  13. Do you need the same number of columns to perform a join?

  14. From the examples given in the chapter, what does the UNION JOIN appear to do?

  15. If a VARCHAR column were unioned with a CHAR column, what would the resulting column be? (Hint: refer to the "Data Type Precedence" section in Chapter 6.)

  16. What does set compatibility mean?

  17. 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?

  18. Do you need the same number of columns to perform an INTERSECT operation?

  19. Do you need the same data types to perform an INTERSECT operation?


Part - 8

  1. What is a subquery?

  2. Which part of the query/subquery is considered the inner query, and which part is considered the outer query?

  3. Can a subquery always be done as a join? Why or why not?

  4. When writing a query that will have a subquery, how do you determine which table/tables will go in the outer query?

  5. Which predicate can usually be reformulated into a join?

  6. When using operators, are many values acceptable from a result of a subquery?

  7. What can you do to insure a working subquery?


Part -9
  1. What do aggregate functions do?

  2. How does the GROUP BY clause work?

  3. What is the difference between a GROUP BY and ORDER BY?

  4. What is the HAVING clause used for?

  5. Can the WHERE clause always be considered a substitute for the HAVING clause? Why or why not?

  6. Do functions of functions have to be handled in a special way in Server SQL 2005?

  7. Will nulls in grouped columns be included in a result set?

  8. How do aggregate functions treat nulls?

  9. Does the sequence of the columns in a GROUP BY clause have an effect on the end result?

  10. When would it not make sense to use the GROUP BY and DISTINCT functions together?

  11. Is GROUP BY affected by nulls?

  12. Which comes first in a SELECT statement, an ORDER BY or GROUP BY? Why?

  13. The GROUP BY and ________________ clauses are used together.


Part -10

  1. What is a noncorrelated subquery?

  2. Which type of subquery can be executed on its own?

  3. Which part of a query is evaluated first, the query or the subquery?

  4. What are correlated subqueries?

  5. What does the EXISTS predicate do?

  6. What are considered universal qualifiers?

  7. Is correlation necessary when we use EXISTS? Why?

  8. Explain how the "for all" type SQL query involves a double-nested correlated subquery using the NOT EXISTS predicate.

1 comment:

Anonymous said...

The title should be "MS-SQL Questions" SQL could mean Oracle, DB2, MYSQL, etc..