What do you know about the Universally Unique Identifier – UUID data type?
When we are declaring a variable using SET or SELECT, What is the performance different between SET and SELECT?
What is the purpose of OPENXML clause SQL server stored procedure?
OPENXML parses the XML data in SQL Server in an efficient manner. It’s primary ability is to insert XML data to the RDB. It is also possible to query the data by using OpenXML. The path of the XML element needs to be specified by using ‘xpath’.
What is the use of @@CPU_BUSY statement?
It returns the time that SQL Server has spent working since it was last started.
Explain the use of keyword WITH ENCRYPTION. Create a Store Procedure with Encryption.
WITH ENCRYPTION indicates that SQL Server will convert the original text of CREATE PROCEDURE statement to an encrypted format. Users that do not have no access to system tables or database files cannot retrieve the encrypted text. However, the text will be available to privileged users.
If you need to script a table with data, how will you do that?
One way to achieve this by using Generate Script Task in SSMS.
Right click on database and then go to Tasks and then go to Generate Scripts.
I have two tables with the same columns and data types. If I need toget distinct records from both of tables how can I do that?
We can use the UNION operators.
Can we send emails in HTML Format from SQL Server, How will you do that?
We can send email from SQL Server in HTML format by using dbo.sp_send_dbmail stored procedure. To send email in HTML format, we have to build the body of email with HTML Tags. The below code can be used to send basis HTML formatted email. If you want to loop through some results of table and send in HTML formatted email.
Can we create triggers on temp table?
No: we cannot create a trigger on temp table.
How would you get the size of a SQL Server Table?
EXEC sp_spaceused ‘TableName’
How would you determine if the expression is Numeric?
ISNUMERIC( ): function is provided to us in SQL Server to check if the expression is valid numeric type or not. As per Microsoft it should work with Integers and Decimal data types and if data is valid integer or decimal, ISNumeric() should return us 1 else 0.
Try_Convert( ): In SQL Server 2012. Microsoft introduced new function call Try_Convert( ). You can use try_convert function to convert to required data type and if it is not able to convert then it will return Null as output.
Which function is used to convert the integer value into spaces?
The SPACE function converts the specified integer value into spaces.
1 SELECT SPACE(8);
What is constant folding?
SQL Server evaluates some constant expression early to improve the query performance. This is called constant folding.
What is a full text search in SQL Server?
Full text indexing is a great feature that solves a database problem, the searching of textual data columns for specific words and phrases in SQL Server databases.
Full Text Index can be used to search words, phrases and multiple forms of a word or phrase using FREETEXT () and CANTAINS () with “and” or “or” operators.
Can you execute full-text queries on a table without full-text index on that column?
No: Before you can run full-text queries on a table, the database administrator must create a full-text index on the table. The full-text index includes one or more character-based columns in the table. These columns can have any of the following data types: char, varchar, nchar, nvarchar, text, ntext, image, xml, or varbinary(max) and FILESTREAM.
Are Full-text queries are case-sensitive?
Full-text queries are not case-sensitive. For example, searching for “DBRND” or “dbrnd” returns the same results.
What is the difference between LIKE and FULL-Text Search?
In contrast to full-text search, the LIKETransact-SQL predicate works on character patterns only. Also, you cannot use the LIKE predicate to query formatted binary data. Furthermore, a LIKE query against a large amount of unstructured text data is much slower than an equivalent full-text query against the same data.
A LIKE query against millions of rows of text data can take minutes to return; whereas a full-text query can take only seconds or less against the same data, depending on the number of rows that are returned.
What is a Full-Text Engine?
The Full-Text Engine in SQL Server is fully integrated with the query processor. The Full-Text Engine compiles and executes full-text queries. As part of query execution, the Full-Text Engine might receive input from the thesaurus and stoplist.
What is the internal process of Full-Text Querying?
- The query processor passes the full-text portions of a query to the Full-Text Engine for processing. The Full-Text Engine performs word breaking and, optionally, thesaurus expansions, stemming, and stopword (noise-word) processing.
- Then the full-text portions of the query are represented in the form of SQL operators, primarily as streaming table-valued functions (STVFs).
- During query execution, these STVFs access the inverted index to retrieve the correct results. The results are either returned to the client at this point, or they are further processed before being returned to the client.
What is CONTAINS and FREETEXT of Full-Text predicates?
The CONTAINS and FREETEXT predicates return a TRUE or FALSE value. They can be used only to specify selection criteria for determining whether a given row matches the full-text query. Matching rows are returned in the result set. CONTAINS and FREETEXT are specified in the WHERE or HAVING clause of a SELECT statement. They can be combined with any of the other Transact-SQL predicates, such as LIKE and BETWEEN.
When using CONTAINS or FREETEXT, you can specify either a single column, a list of columns, or all columns in the table to be searched.
What it is not recommended to name the user defined Stored Procedures with sp_?
They are system defined and mostly resides under the master database so if we write a user defined stored procedure by the name sp_ the query engine will first search the Stored Procedure in the master database and if not found then it will search in the current session database.
This brings unnecessary round trip and reduce the overall performance of user defined stored procedures.
Can we use the PRINT statement in SQL Server Function?
No: We cannot use it.
If you are working on a SQL database and if suddenly a developer changes the code and your queries results start giving errors, how will you check using a T-SQL query (on system tables) that what has changed in the database.
select o.name, o.object_id, o.modify_date, c.text
from sys.objects o
join sys.syscomments c
on o.object_id = c.id