Click here to get free chapters (PDF) in the mailbox
Please read the Introductory Post before continue reading interview question and answers.
List of all the Interview Questions and Answers Series blogs
How will you Handle Error in SQL SERVER 2008?
SQL Server now supports the use of TRY…CATCH constructs for providing rich error handling. TRY…CATCH lets us build error handling at the level we need, in the way we need to by setting a region where if any error occurs, it will break out of the region and head to an error handler. The basic structure is as follows:
BEGIN TRY <code> END TRY BEGIN CATCH <code> END CATCH
So if any error occurs in the TRY block, then execution is diverted to the CATCH block, and the error can be resolved.
What is RAISEERROR?
RaiseError generates an error message and initiates error processing for the session. RAISERROR can either reference a user-defined message stored in the sys.messages catalog view or build a message dynamically. The message is returned as a server error message to the calling application or to an associated CATCH block of a TRY…CATCH construct. (Read more here)
How to Rebuild the Master Database?
Master database is system database and it contains information about running server’s configuration. When SQL Server 2005 is installed, it usually creates master, model, msdb, tempdb, resourcedb and the distribution system database by default. Only the Master database is the one which is absolutely a must-have database. Without the Master database, the SQL Server cannot be started. This is the reason why it is extremely important to backup the Master database.
To rebuild the Master database, run Setup.exe, verify, and repair a SQL Server instance, and rebuild the system databases. This procedure is most often used to rebuild the master database for a corrupted installation of SQL Server. (Read more here)
What is the XML Datatype?
The xml data type lets you store XML documents and fragments in a SQL Server database. An XML fragment is an XML instance that has a missing single top-level element. You can create columns and variables of the xml type and store XML instances in them. The xml data type and associated methods help integrate XML into the relational framework of SQL Server.
What is Data Compression?
In SQL SERVE 2008, Data Compression comes in two flavors:
- Row Compression
- Page Compression
Row Compression
Row compression changes the format of physical storage of data. It minimize the metadata (column information, length, offsets etc) associated with each record. Numeric data types and fixed-length strings are stored in variable-length storage format, just like Varchar. (Read more here)
Page Compression
Page compression allows common data to be shared between rows for a given page. It uses the following techniques to compress data:
- Row compression.
- Prefix Compression. For every column in a page, duplicate prefixes are identified. These prefixes are saved in compression information headers which resides after the page header. A reference number is assigned to these prefixes and that reference number is replaced where ever those prefixes are being used.
Dictionary Compression
Dictionary compression searches for duplicate values throughout the page and stores them in CI. The main difference between prefix and dictionary compression is that the former is only restricted to one column while the latter is applicable to the complete page.
What is Use of DBCC Commands?
The Transact-SQL programming language provides DBCC statements that act as Database Console Commands for SQL Server. DBCC commands are used to perform the following tasks.
- Maintenance tasks on database, index, or filegroup.
- Tasks that gather and display various types of information.
- Validation operations on a database, table, index, catalog, filegroup, or allocation of database pages.
- Miscellaneous tasks such as enabling trace flags or removing a DLL from memory. (Read more here)
How to Copy the Tables, Schema and Views from one SQL Server to Another?
There are multiple ways to do this.
- “Detach Database” from one server and “Attach Database” to another server.
- Manually script all the objects using SSMS and run the script on a new server.
- Use Wizard of SSMS. (Read more here)
How to Find Tables without Indexes?
Run the following query in the Query Editor.
USE <database_name>;
GO
SELECT SCHEMA_NAME(schema_id) AS schema_name
,name AS table_name
FROM sys.tables
WHERE OBJECTPROPERTY(OBJECT_ID,'IsIndexed') = 0
ORDER BY schema_name, table_name;
GO
List of all the Interview Questions and Answers Series blogs
Reference: Pinal Dave (https://blog.sqlauthority.com)