Introduction to TSQL Interview Questions And Answers
If you are looking for a job that is related to TSQL, you need to prepare for the 2023 TSQL Interview Questions. Though every interview is different and the scope of a job is also different, we can help you out with the top TSQL Interview Questions and answers, which will help you take the leap and get you success in your TSQL Interview.
Below is the list of Important 2023 TSQL Interview Questions that are asked mostly in an interview
Part #1 – TSQL Interview Questions And Answers (Basic)
Below are the basic interview questions and answers
1. Explain what is T-SQL?
Answer:
T-SQL stands for Transact-Structured Query Language, which is an extension of SQL functionality supported by Microsoft SQL Server and Sybase ASE.
2. Explain what are the differences between SQL and T-SQL?
Answer:
The difference between T-SQL and SQL is that SQL is a query language to operate on sets, while TSQL is a proprietary procedural language used by MS SQL Server. Also, T-SQL has a different implementation of DELETE and UPDATE than SQL.
3. Please name at least five commands which can manipulate text in the T-SQL code. For example, replace a text string, obtain a portion of the text, etc.
Answer:
•LEFT(character_expression, integer_expression ) – It returns the left part of a character expression with the specified number of characters.
•CHARINDEX( findTextData, text data, [startingPosition] ) – It returns starting position of an expression in a character string, and starting position is optional.
•REPLACE( textData, findTextData, replaceWithTextData ) – It replaces a new value for occurrences of text found in the string.
•REVERSE( character_expression ) – It returns the reverse of a character expression.
•LEN( textData ) – It returns the length of the string, excluding trailing blanks.
•LOWER ( character_expression ) – After converting an uppercase character to lowercase, it will return a character expression.
•LTRIM( textData) – Leading blanks will be removed.
•PATINDEX( findTextData, textData ) – It returns the starting position integer value of text found in the string.
•REPLICATE(character_expression, integer_expression ) – It repeats a character expression for a specified number of times.
•RTRIM( textData) – Removes trailing blanks. SPACE( number of spaces ) – It repeats the space value specified a number of times.
•STUFF( textData, start, length, insert text data ) – It deletes a specified length of characters and inserts another set of characters at a specified starting point.
•SUBSTRING( textData, startPosition, length ) – It returns portion of the string.
•UPPER( character_expression ) – It returns a character expression with lowercase character to uppercase.
4. Is it possible to import data directly from T-SQL commands without using SQL Server Integration Services? If so, what are the commands?
Answer:
Yes – There are Six commands available to import data directly into the T-SQL language. These commands include:
•BCP
•Bulk Insert
•OpenRowSet
•OPENDATASOURCE
•OPENQUERY
•Linked Servers
5. Mention what is ‘GO’ in T-SQL?
Answer:
‘GO’ is not a Transact-SQL statement but a batch separator. It is a command identified by the sqlcmd and osql utilities and SQL Server Management Studio Code editor. SQL Server utilities read “GO” as a signal that they should send the current batch of TSQL statements to an instance of SQL Server.
6. Mention the difference between the DELETE statement and TRUNCATE statement?
Answer:
With the use of the DELETE and TRUNCATE command, all data will be lost in a table. The difference between the DELETE statement and TRUNCATE statement is that,
•DELETE is used for conditional removal of data records from Tables. These operations are logged.
•TRUNCATE is used for the unconditional removal of data records from Tables. Truncate operations are not logged.
Part #2- TSQL Interview Questions And Answers (Advanced)
Below are the advanced interview questions and answers
7.When to use COALESCE() & ISNULL() Functions?
Answer:
The NULLability of result expression is different for ISNULL and COALESCE. The ISNULL return value is always considered NOT NULLable (assuming the return value is a non-nullable one), whereas COALESCE is not. So the expressions ISNULL(NULL, 1) and COALESCE(NULL, 1), although equivalent, has different NULLability values. This makes a difference if you are using these expressions in computed columns and creating key constraints or making the return value of a scalar UDF deterministic so that it can be indexed.
8. Mention what is sub-query?
Answer:
A sub-query is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved. A sub-query can be used with the statements like Update, select, delete and insert with the operators like =, >, <, >=,<=, etc.
9. What are the types of XML indexes in SQL Server?
Answer:
Microsoft SQL Server supports different types of XML indexes. An XML index is different from a relational index. There are basically TWO types of XML Indexes viz., Primary XML Indexes and Secondary XML indexes. The primary XML index is a clustered index on an internal table known as the node table that users cannot use directly from their T-SQL statements. To enhance search performance, we create secondary XML indexes. These create secondary links (RID) at leaf level for existing clustered index-based KEY pages. A primary XML index should be created prior to creating the Secondary XML Indexes.
10. What is SQL Server?
Answer:
SQL Server is a vast, easy, powerful Relational Database Management (also Data warehouse Management) application from Microsoft. It offers Database Development, Database Management, and Business Intelligence capabilities. This wonderful technology is very easy to master and manage. This offers the following advantages:
•Easy To Use
•Support for Small, Medium and Large Database Storage
•Cheaper, compared to other RDBMS
•Data warehouse Support
•Enhanced Security Features
•Enterprise Feature Support
•In-Memory Processing
•Business Intelligence Support
•Highly Scalable and Powerful
•Low Cost of Ownership
11. Mention new error handling commands which are introduced with the SQL Server 2005 and beyond? What commands did they replace? How is the command used?
Answer:
The new commands introduce with SQL Server 2005 are TRY and CATCH. Though they do not replace directly any specific command, but in many aspects, TRY and CATCH can be used instead of RAISERROR. The TRY block covers business logic, whereas the CATCH logic is for capturing the error.
12. Mention what TOP is in TSQL?
Answer:
TOP limits the rows returned in a query result set to a specified number of rows or percentage of rows in SQL Server. When TOP is used in combination with the ORDER BY clause, the result set is limited to the first N number of ordered rows. Otherwise, it retrieves the first N number of rows in an undefined order.
Recommended Article
This has been a guide to the List Of TSQL Interview Questions and answers so that the candidate can crackdown on these Interview Questions easily. This is the most useful and valuable post on TSQL Interview Questions and answers. You may also look at the following articles to learn more –
- SSIS Interview Questions And Answer
- Cognos Interview Questions And Answer
- SSAS Interview Questions And Answer
- OBIEE Interview Questions
41 Online Courses | 13 Hands-on Projects | 322+ Hours | Verifiable Certificate of Completion
4.5
View Course
Related Courses