SQL Server Database Optimization and Query Fundamentals
Test your knowledge of SQL Server database concepts including indexes, query optimization, performance tuning, DDL operations, and SQL syntax
Questions
What are the situations when an index might not be picked up?
- Leading column in the index is not part of the search arguments
- Data types are not matching while doing a join
- Optimizer decides that table scan is better
- Index name is improper
Microsoft recommends a clustered index in every SQL Server table
- True
- False
A column in a table, having millions of rows, contains the name of States in India. It is defined as CHAR(50). What performance improvements can be made with respect to the data type?
- Change it to CHAR(10)
- Change it to VARCHAR(50)
- Change it to NVARCHAR(50)
- Change it to CHAR(100)
Numeric columns are best suited to define an index (for faster access)
- True
- False
In a SQL Server 2005 query plan, the presence of which of the below items are indicators of potential performance issues?
- Index scan
- Table scan
- Bookmark lookup
- Index seek
During performance tuning, it is imperative that we have data regarding the pain points (slow performing queries, high CPU utilizing queries, etc.). What tools are useful in getting these info?
- Dynamic Management Views (DMV)
- DBCC commands
- Query plans
- BCP
In a query, Table_A is joined with Table_B based on the join criteria (Table_A.Column_1 = Table_B.Column_1). The SME in the team mentions that Table_B is the child of Table_A based on Column_1 (one-to-many relationship) and should always have value. Given these considerations, which of the following doesn't apply to this situation?
- There needs to be a Foreign Key relationship between the two tables.
- Table_B.Column_1 shouldn't have NULL values.
- There should be a clustered index on Table_A.Column_1 and a non-clustered index on Table_B.Column_1.
- Table_B.Column_1 should be unqiue.
In Accounts_History table, among many columns, I have the Account_ID (Primary Key) and Trans_Date. There is a query that runs frequently to know the latest transaction that was done on the account. Which one of the below approaches will be most beneficial in this case?
- Defining a clustered index on Account_ID
- Defining a clustered index on Account_ID, Trans_Date
- Defining a non-clustered index on Account_ID, Trans_Date
- Don't define any indexes
There are 10 tables with similar structure but mutually exclusive records. A query needs to fetch some records from each of these tables. Which of the following is the best approach to do this?
- Use UNION between the 10 SELECT statements
- Execute separate SQL statements and let the front-end merge the results
- Use UNION ALL between the 10 SELECT statements
- Define a temporary table and populate it with data from the 10 SELECT statements and then do a single SELECT from this table
Always use hints while writing queries (e.g. WITH NOLOCK, WITH UPDLCK) since it will help the query optimizer
- True
- False
Please see the below query: create table employee (emp_id number(6) primary key, emp_name varchar2(20)); rollback; What will the result of the below query: desc employee;
- It will describe the table.
- It will return ar error:'Table or view does not exist'
- The query is not correct.
- None of the above
We can use group by clause with:
- Non aggregate functions only
- Aggregate functions only
- Both 1 & 2
- None of the above
Which of the below is the correct query to update the columns of a table:
- update table TABLE_NAME set COMLUMN_NAME=<new values> where <conditions>
- update TABLE_NAME set COMLUMN_NAME=<new values> where <conditions>
- Both 1 & 2 are correct
- None of the above
UNION query returns only distinct rows and UNION ALL may return duplicates.
- True
- False
Bitmap index is suitable for the tables having huge and repeatative(duplicates) data.
- True
- False
SPLIT function is available in SQL server 2005?
- True
- False
DDL means?
- Data Dynamic Link
- Data Description Language
- Data Definition Language
- Data Definition Link
Which inbuilt SP is used to parse the values from XML document
- sp_xml_postdocument
- sp_xml_readdocument
- sp_xml_loaddocument
- sp_xml_preparedocument
Which command is used to Check integrity of a table or indexed view?
- DBCC CHECKIDENT
- DBCC CHECKTABLE
- DBCC CHECKALLOC
- DBCC CHECKINTEG