MS SQL Server developer interview 1. Which of the following has the highest order of precedence? o Functions and Parenthesis o Multiplication, Division and Exponents o Addition and Subtraction o Logical Operations 2. When designing a database table, how do you avoid missing column values for non-primary key columns? o Use UNIQUE constraints o Use PRIMARY KEY constraints o Use DEFAULT and NOT NULL constraints o Use FOREIGN KEY constraints o Use SET constraints 3. Which of the following is the syntax for creating an Index? o CREATE [UNIQUE] INDEX index_name OF tbl_name (index_columns) o CREATE [UNIQUE] INDEX OF tbl_name (index_columns) o CREATE [UNIQUE] INDEX ON tbl_name (index_columns) o CREATE [UNIQUE] INDEX index_name ON tbl_name (index_columns) 4. Which of the following is not a valid character datatype in SQL Server? o BLOB o CHAR o VARCHAR o TEXT o VARTEXT 5. Which of the following statements about SQL Server comments is false? o /* … */ are used for multiline comments o // is used for single line comments o – is used for single line comments o Nested comments are allowed i.e. /* comment 1 /* comment 2 */ comment 1*/ o ‘ is used for single line comments 6. Consider the following transaction code: Begin Transaction Update names_table set employee_name = "Ramesh" where employee_name = "Mahesh" Save Transaction SAVE_POINT Update salaries set salary=salary + 900 where employee_job = "Engineer" Rollback transaction Commit transaction
What will be the result produced by this transaction? o “Ramesh” will be updated to “Mahesh”, but salaries of engineers will not be updated
o o
Neither “Ramesh” will be updated to “Mahesh”, nor the salary of engineers will be updated. “Ramesh” will be updated to “Mahesh” and salary of engineers will also be updated.
7. Which of the following constraints can be used to enforce the uniqueness of rows in a table? o DEFAULT and NOT NULL constraints o FOREIGN KEY constraints o PRIMARY KEY and UNIQUE constraints o IDENTITY columns o CHECK constraints 8. Which of the following are not date parts? o quarter o dayofweek o dayofyear o weekday 9. The IF UPDATE (column_name) parameter in a trigger definition will return TRUE in case of an INSERT statement being executed on the triggered table: o Yes o No o It returns TRUE only if an UPDATE query is executed o Both b and c 10. Which one of the following must be specified in every DELETE statement? o Table Name o Database name o LIMIT clause o WHERE clause o Column Names 11. Which one of the following correctly selects rows from the table myTable that have null in column column1? o SELECT * FROM myTable WHERE column1 is null o SELECT * FROM myTable WHERE column1 = null o SELECT * FROM myTable WHERE column1 EQUALS null o SELECT * FROM myTable WHERE column1 NOT null o SELECT * FROM myTable WHERE column1 CONTAINS null 12. Is this statement true or false: A cursor is a pointer that identifies a specific working row within a set o True o False 13. Which of the following commands is used to change the structure of table? o CHANGE TABLE o MODIFY TABLE o ALTER TABLE
UPDATE TABLE 14. Consider the following statements and pick the correct answer: o
1. ceiling() - returns the smallest integer greater than or equal to the specified value 2. floor() - returns the largest integer less than or equal to the specified value o 1 is true and 2 is false o 1 is false and 2 is true o Both 1 and 2 are true o Both 1 and 2 are false
15. What is the correct SQL syntax for returning all the columns from a table named “Persons” sorted REVERSE alphabetically by “FirstName”? o SELECT * FROM Persons WHERE FirstName ORDER BY FirstName DESC o SELECT * FROM Persons SORT REVERSE ‘FirstName’ c . SELECT * FROM Persons ORDER BY ‘FirstName’ o
SELECT * FROM Persons ORDER BY FirstName DESC SELECT * FROM Persons ORDER BY DESC FirstName
16. What is the maximum value that can be stored for a datetime field? o Dec 31, 9999 o Jun 6, 2079 o Jan 1, 2753 o Jan 1, 2100 17. Consider the following queries:
1. select * from employee where department LIKE "[^F-M]%"; 2. select * from employee where department = "[^F-M]%";
Select the correct option: o Query 2 will return an error o Both the queries will return the same set of records o Query 2 is perfectly correct o Query 2 would return one record less than Query 1 18. How can you view the structure of a table named “myTable” in SQL Server? o desc myTable o desc table myTable o sp_columns myTable o None of the above o Using either option a or c 19. What does referential integrity (also called relational integrity) prevent? o Loss of data from employee sabotage o Loss of data from any one corrupted table o Recursive joins o One-to-many or many-to-many relationships between columns in a table
Data redundancy 20. Which of the following is not a global variable? o @@colcount o @@error o @@rowcount o @@version o All are valid global variables 21. Consider the following two tables: o
1. customers( customer_id, customer_name) 2. branch ( branch_id, branch_name ) What will be the output if the following query is executed: Select * branch_name from customers,branch o It will return the fields customer_id, customer_name, branch_name o It will return the fields customer_id, customer_name, branch_id,
branch_name o It will return the fields customer_id, customer_name, branch_id, branch_name, branch_name o It will return an empty set since the two tables do not have any common field name o It will return an error since * is used alone for one table only 22. Which of the following is not a control statement? o if…else o if exists o do…while o while o begin…end 23. Which of the following is not a valid Numeric datatypes in SQL Server? o INT o SMALLINT o TINYINT o BIGINT o MONEY 24. Which of the following datatypes is not supported by SQL-Server? o Character o Binary o Logical o Date o Numeric o All are supported 25. What will the output be if you try to perform arithmetic on NULL values? o 0 o NULL o It will generate an error message o Can’t be determined 26. Which of the following options is not correct about the DATEDIFF() function?
It returns the difference between parts of two specified dates It takes three arguments It returns a signed integer value equal to second date part minus first date part o It returns a signed integer value equal to first date part minus second date part 27. Sample Code o o o
CREATE TABLE table1( column1 varchar(50), column2 varchar(50), column3 varchar(50), column4 varchar(50));
Which one of the following is the correct syntax for adding the column named “column2a” after column2 to the table shown above? o ALTER TABLE table1 ADD column2a varchar(50) AFTER column2; o MODIFY TABLE table1 ADD column2a AFTER column2; o INSERT INTO table1 column2a AS varchar(50) AFTER column2; o ALTER TABLE table1 INSERT column2a varchar(50) AFTER column2; o CHANGE TABLE table1 INSERT column2a BEFORE column3; 28. State which of the following are true o Views are a logical way of looking at the logical data located in the tables o Views are a logical way of looking at the physical data located in the tables o Tables are physical constructs used for storage and manipulation of data in databases o Tables are logical constructs used for storage and manipulation of data in databases 29. Which of the following is not a valid binary datatype in SQL Server? o BINARY o VARBINARY o BIT o IMAGE o TESTAMP 30. Which of the following is false with regards to sp_help? o When a procedure name is passed to sp_help, it shows the parameters o When a table name is passed to sp_help, it shows the structure of the table o When no parameter is passed, it provides a list of all objects and userdefined datatypes in a database o All of the above are true o Which of the following are false for batches (batch commands)? Statements in a batch are parsed, compiled and executed as a group None of the statements in the batch is executed if there are any syntax errors in the batch None of the statements in the batch is executed if there are any parsing errors in the batch
None of the statements in the batch is executed if there are any fatal errors in the batch o Select the correct option: Optimistic locking is a locking scheme handled by the server, whereas pessimistic locking is handled by the application developer Pessimistic locking is a locking scheme handled by the server, whereas optimistic locking is handled by the application developer 31. 2. When designing a database table, how do you avoid missing column values for non-primary key columns?
Ans. Use DEFAULT and NOT NULL constraints 3. Which of the following is the syntax for creating an Index? Ans. CREATE [UNIQUE] INDEX ON tbl_name (index_columns) 4. Which of the following is not a valid character datatype in SQL Server? Ans. VARTEXT 6. Consider the following transaction code: Begin Transaction Update names_table set employee_name = “Ramesh” where employee_name = “Mahesh” Save Transaction SAVE_POINT Update salaries set salary=salary + 900 where employee_job = “Engineer” Rollback transaction Commit transaction What will be the result produced by this transaction? Ans. “Ramesh” will be updated to “Mahesh”, but salaries of engineers will not be updated. 7. Which of the following constraints can be used to enforce the uniqueness of rows in a table? Ans. PRIMARY KEY and UNIQUE constraints 8. Which of the following are not date parts? Ans. dayofweek 10. Which one of the following must be specified in every DELETE statement?
Ans. Table Name 11. Which one of the following correctly selects rows from the table myTable that have null in column column1? Ans. SELECT * FROM myTable WHERE column1 is null 12. Is this statement true or false: A cursor is a pointer that identifies a specific working row within a set Ans. True 13. Which of the following commands is used to change the structure of table? Ans. ALTER Table 14. Consider the following statements and pick the correct answer: 1. ceiling() - returns the smallest integer greater than or equal to the specified value 2. floor() - returns the largest integer less than or equal to the specified value Ans. Both 1 and 2 are true 15. What is the correct SQL syntax for returning all the columns from a table named “Persons” sorted REVERSE alphabetically by “FirstName”? Ans. SELECT * FROM Persons ORDER BY FirstName DESC 16. What is the maximum value that can be stored for a datetime field? Ans. Dec 31, 9999 18. How can you view the structure of a table named “myTable” in SQL Server? Ans. desc myTable 19.What does referential integrity (also called relational integrity) prevent? Ans. One-to-many or many-to-many relationships between columns in a table 20.Which of the following is not a global variable? Ans.@@colcount 21. Consider the following two tables:
1. customers( customer_id, customer_name) 2. branch ( branch_id, branch_name ) What will be the output if the following query is executed: Select * branch_name from customers,branch Ans. none of all 22. Which of the following is not a control statement? Ans. if exists 23. Which of the following is not a valid Numeric datatypes in SQL Server? Ans. 24.Which of the following datatypes is not supported by SQL-Server? Ans. Logical 25. What will the output be if you try to perform arithmetic on NULL values? Ans.NULL 26. What will the output be if you try to perform arithmetic on NULL values? Ans. It returns a signed integer value equal to first date part minus second date part 27. Sample Code CREATE TABLE table1( column1 varchar(50), column2 varchar(50), column3 varchar(50), column4 varchar(50)); Which one of the following is the correct syntax for adding the column named “column2a” after column2 to the table shown above? Ans. none of all 29. Which of the following is not a valid binary datatype in SQL Server? Ans. TESTAMP Tech Interviews comment by Baljeet Chawla
32. Correct Answer of Question 3 is : CREATE [UNIQUE] INDEX index_name ON tbl_name (index_columns) bz it required the name of the index. Thanks. Tech Interviews comment by Rajesh S. Chandan 33. When designing a database table, how do you avoid missing column values for non-primary key columns? Use DEFAULT and NOT NULL constraints Which of the following is the syntax for creating an Index? CREATE [UNIQUE] INDEX index_name ON tbl_name (index_columns) Which of the following is not a valid character datatype in SQL Server? BLOB VARTEXT Which of the following statements about SQL Server comments is false? – is used for single line comments ‘ is used for single line comments Begin Transaction Update names_table set employee_name = “Ramesh” where employee_name = “Mahesh” Save Transaction SAVE_POINT Update salaries set salary=salary + 900 where employee_job = “Engineer” Rollback transaction Commit transaction What will be the result produced by this transaction? Neither “Ramesh” will be updated to “Mahesh”, nor the salary of engineers will be updated. Which of the following constraints can be used to enforce the uniqueness of rows in a table? PRIMARY KEY and UNIQUE constraints Which of the following are not date parts? dayofweek The IF UPDATE (column_name) parameter in a trigger definition will return TRUE in case of an INSERT statement being executed on the triggered table: No
Which one of the following must be specified in every DELETE statement? Table Name Which one of the following correctly selects rows from the table myTable that have null in column column1? SELECT * FROM myTable WHERE column1 is null Is this statement true or false: A cursor is a pointer that identifies a specific working row within a set True Which of the following commands is used to change the structure of table? ALTER TABLE Consider the following statements and pick the correct answer: 1. ceiling() - returns the smallest integer greater than or equal to the specified value 2. floor() - returns the largest integer less than or equal to the specified value Both 1 and 2 are true What is the correct SQL syntax for returning all the columns from a table named “Persons” sorted REVERSE alphabetically by “FirstName”? SELECT * FROM Persons WHERE FirstName ORDER BY FirstName DESC What is the maximum value that can be stored for a datetime field? Dec 31, 9999 Consider the following queries: 1. select * from employee where department LIKE “[^F-M]%”; 2. select * from employee where department = “[^F-M]%”; Select the correct option: Query 2 will return an error How can you view the structure of a table named “myTable” in SQL Server? None of the above What does referential integrity (also called relational integrity) prevent? Data redundancy Which of the following is not a global variable? @@colcount Consider the following two tables: 1. customers( customer_id, customer_name) 2. branch ( branch_id, branch_name )
What will be the output if the following query is executed: Select * branch_name from customers,branch It will return an error since * is used alone for one table only Which of the following is not a control statement? begin…end Which of the following is not a valid Numeric datatypes in SQL Server? TINYINT Which of the following datatypes is not supported by SQL-Server? Logical What will the output be if you try to perform arithmetic on NULL values? NULL Which of the following options is not correct about the DATEDIFF() function? It returns the difference between parts of two specified dates It takes three arguments It returns a signed integer value equal to second date part minus first date part CREATE TABLE table1( column1 varchar(50), column2 varchar(50), column3 varchar(50), column4 varchar(50)); Which one of the following is the correct syntax for adding the column named “column2a” after column2 to the table shown above? Nothing not possible through Query Analyzer. State which of the following are true Views are a logical way of looking at the logical data located in the tables Which of the following is not a valid binary datatype in SQL Server? IMAGE Which of the following is false with regards to sp_help? When a procedure name is passed to sp_help, it shows the parameters When a table name is passed to sp_help, it shows the structure of the table When no parameter is passed, it provides a list of all objects and user-defined datatypes in a database All of the above are true
Which of the following are false for batches (batch commands)? Statements in a batch are parsed, compiled and executed as a group None of the statements in the batch is executed if there are any syntax errors in the batch None of the statements in the batch is executed if there are any parsing errors in the batch None of the statements in the batch is executed if there are any fatal errors in the batch Select the correct option: Pessimistic locking is a locking scheme handled by the server, whereas optimistic locking is handled by the application developer Please send me the comments by mail if you are not agree with me. Thank you very much for your passion. Rajesh Tech Interviews comment by Rajesh S. Chandan 34. 18. How can you view the structure of a table named “myTable” in SQL Server? a.desc myTable b.desc table myTable c.sp_columns myTable d.None of the above e.Using either option a or c Ans. c. sp_columns myTable (Verified and Tested Ok.) by Sudhir Malik (IIT Roorkee, Graduate) Tech Interviews comment by Sudhir Malik 35. what is the difference between primarykey and foreignKey in mssql Tech Interviews comment by sumith 36. Which of the following has the highest order of precedence? Functions and Parenthesis Multiplication, Division and Exponents Addition and Subtraction Logical Operations Functions and Parenthesis Tech Interviews comment by mdate
37. Which of the following commands is used to change the structure of table? * ALTER TABLE Tech Interviews comment by Joe Gakenheimer 38. 18. How can you view the structure of a table named “myTable” in SQL Server? a.desc myTable b.desc table myTable c.sp_columns myTable d.None of the above e.Using either option a or c Ans. c. sp_columns myTable or else you can also use sp_help mytable Tech Interviews comment by Prateek Arora 39. How duplicate record will be delete in sql2000? Tech Interviews comment by srinivasa rao