SQL Database Concepts Interview Preparation Guide
Download PDF

SQL Database Concepts frequently Asked Questions by expert members with experience in Basic SQL Database Concepts. These interview questions and answers on SQL Database Concepts will help you strengthen your technical skills, prepare for the interviews and quickly revise the concepts. So get preparation for the SQL Database Concepts job interview

113 Basic SQL Server Questions and Answers:

Table of Contents:

Number 1  Basic SQL Server Job Interview Questions and Answers
Number 1 Basic SQL Server Job Interview Questions and Answers

1 :: What is buffer cash and log Cache in sql server?

Buffer Cache: Buffer cache is a memory pool in which data pages are read. It performance of the buffer cache is indicated as follows: 95% indicates that pages that were found in the memory are 95% of time. Another 5% is needed for physical disk access. If the value falls below 90%, it is the indication of more physical memory requirement on the server.

Log Caches: Log cache is a memory pool used to read and write the log pages. A set of cache pages are available in each log cache. The synchronization is reduced between log and data buffers by managing log caches separately from the buffer cache.

2 :: Do you know what is a Trace frag? Where do we use it?

Temporary setting of specific server characteristics is done by trace tags. DBCC TRACEON is the command to set the trace flags. Once activated, trace flag will be in effect until the server is restarted. Trace frags are frequently used for diagnosing performance issues.

For example, the trace flag 3205 is used for disabling hard compression for tape drives, when an instance of SQL Server starts.

3 :: Explain difference between cross join and Full outer join?

Cross Join :
No join conditions are specified.
Results in pairs of rows.
Results in Cartesian product of two tables.

Full Outer Join:
A combination of both left and right outer joins.
Results in every row from both of the tables , at least once.
Assigns NULL for unmatched fields.

4 :: Do you know how to send email from database?

SQL Server has a feature for sending mail. Stored procedures can also be used for sending mail on demand. With SQL Server 2005, MAPI client is not needed for sending mails.

The following is the process for sending emails from database.

- Make sure that the SQL Server Mail account is configured correctly and enable Database Mail.

- Write a script to send an e-mail. The following is the script.

USE [YourDB]
EXEC msdb.dbo.sp_send_dbmail
@recipients = 'xyz@xyz.com; xyz@xyz.com;abc@edf.com’
@body = ' A warm wish for your future endeavor',
@subject = 'This mail was sent using Database Mail' ;
GO

5 :: Do you know how to make remote connection in database?

The following is the process to make a remote connection in database:

Use SQL Server Surface Area Configuration Tool for enabling the remote connection in database.
Click on Surface Area Configuration for Services and Connections.
Click on SQLEXPRESS/Database Engine/RemoteConnections
Select the radio button: Local and Remote Connections and select ‘Using TCP/IP only’ under Local and Remote Connections.
Click on OK button / Apply button

6 :: Explain how to use Linked Server?

MS SQL Server supports the connection to different OLE DB on an ad hoc basis. This persistent connection is referred as Linked Server.

The following are the steps to use Linked Server for any OLE DB. I refer this to use an MS-Excel workbook.

Open SQL Server Management Studio in SQL Server 2005
Expand Server Objects in Object Explorer.
Right-click on Linked Servers. Click on New Linked Server.
Select General page in the left pane and
i. Type any name for the linked server in the first text box
ii. Select the Other Data Source option.
iii. Click on Microsoft Jet 4.0 OLE DB Provider from the Provider list.
iv. Type the Excel as the name of the OLE DB data source.
v. Type the full path and file name of the Excel file in Data Source box.
vi. Type the Excel version no. (7.0, 8.0 etc) in the Provider String. Use Excel 8.0 for Excel 2000, Excel 2002 or Excel 97.
vii. To create a linked server click on OK.

7 :: Do you know concepts and capabilities of SQL Server?

Microsoft SQL server is a relational database management system. It uses MS- SQL as the query language. SQL Server offers a high level of security, reliability and scalability depending on the business needs. The server offers a wide data storage, full text query search, buffer management, logging and transaction, fast data retrieval etc. it offers a variety of replication services to avoid loosing data. It offers SQL Server Reporting Services for data gathered from the database.

8 :: Tell me what is the order in which the SQL query is executed?

The following is the order of executing SQL query:

The query goes to the shared pool that has information like parse tree and execution plan for the corresponding statement.

Then validates the SQL statement and validates the source(table).

Acquire locks.

Checks all the privileges.

Execute the query.

Fetch the values for SELECT statement

Displays the fetched values.

To sum up, the sequence is:

SELECT .........
FROM ..........
WHERE ..........
GROUP BY ...........
HAVING .............

9 :: How to store pdf file in sql server?

Create a column as type ‘blob’ in a table. Read the content of the file and save in ‘blob’ type column in a table.

Or store them in a folder and establish the pointer to link them in the database.

10 :: Tell me what is the STUFF and how does it differ from the REPLACE function?

Both STUFF and REPLACE are used to replace characters in a string.

select replace('abcdef','ab','xx') results in xxcdef

select replace('defdefdef','def','abc') results in abcabcabc
We cannot replace a specific occurrence of “def” using REPLACE.

select stuff('defdefdef',4, 3,'abc') results in defabcdef

where 4 is the character to begin replace from and 3 is the number of characters to replace.

11 :: What is BCP?

It is used to copy huge amount of data from tables and views.
It does not copy the structures same as source to destination.

12 :: Explain what are the different index configurations a table can have?

No indexes
A clustered index
A clustered index and many nonclustered indexes
A nonclustered index
Many nonclustered indexes

13 :: Tell me what is de-normalization and what are some of the examples of it?

De-normalization is used to optimize the readability and performance of the database by adding redundant data. It covers the inefficiencies in the relational database software. De-normalization logical data design tend to improve the query responses by creating rules in the database which are called as constraints.
Examples include the following:
- Materialized views for implementation purpose such as:
- Storing the count of “many” objects in one-to-many relationship
- Linking attribute of one relation with other relations
- To improve the performance and scalability of web applications

14 :: Tell me what is normalization? Explain different forms of normalization?

Normalization is a process of organizing the data to minimize the redundancy in the relational database management system (RDBMS). The use of normalization in database is to decompose the relations with anomalies to produce well structured and smaller relations. There are 6 forms of normalization which are as follows:-
- 1NF represents a relation with no repeating groups
- 2NF represents no non-prime attribute in the table
- 3NF defines that every non-prime attribute is non-transitively dependent on every candidate key
- 4NF defines that every non-trival multi-valued dependency in table is dependent on superkey.
- 5NF defines that every non-trival join dependency in table is implied by superkey in table.
- 6NF defines that a table features no non-trival join dependency.

15 :: Tell me what is the difference between Locking and multi-versioning?

Locking is a means of not allowing any other transaction to take place when one is already in progress. In this the data is locked and there won’t be any modification taking place till the transaction either gets successful or it fails. The lock has to be put up before the processing of the data whereas
Multi-versioning is an alternate to locking to control the concurrency. It provides easy way to view and modify the data. It allows two users to view and read the data till the transaction is in progress.

16 :: Do you know what are ACID properties?

ACID is used in database and it includes the following properties such as atomicity, consistency, isolation and durability. These properties allow easy, reliable and secure database transaction. Example: Transfer of money from one bank account to another. It is used to manage the concurrency in the database table.

17 :: Explain candidate key, alternate key, and composite key?

- Candidate Key is a key which provides the uniqueness of the column(s). It identifies each row of a table as unique. It can become the primary key of the table as well. Every tabular relationship will have atleast one candidate key.
- Alternate Key is a type of candidate key which is formed when there are more than one candidate key and one of them is a primary key then other keys will act as an alternate keys. Unique keys also termed as alternate keys which prevent incorrect data from entering the table.
- Composite Key is a special type of candidate key as it is formed by combining two or more columns. This gives assurance of uniqueness of data when the columns are joined together.

18 :: Do you know what is bit data type and whats the information that can be stored inside a bit column?

- Bit data type is the smallest type used in a language. It is used to store the boolean information of the form 1 (true) or 0 (false). The former versions of SQL server doesn’t support NULL type in this but recent version such as SQL server 7.0 onwards it supports NULL state as well.

19 :: What is the difference between a primary key and a unique key?

- Primary key is a combination of columns which uniquely specify a row whereas a unique key is related to the superkey and can uniquely identify each row in the table.
- Primary can only be one in each table as it is one of the special cases of the unique key whereas a unique key can be many.
- Primary key enforces the NOT NULL constraint whereas unique key doesn’t. Due to this values in the unique key columns may or may not be NULL.

20 :: Explain what is RAID and what are different types of RAID levels?

RAID stands for Redundant array of independent disks which was earlier called as Redundant array of inexpensive disks. It is a storage technology that has one logical unit consisting of multiple disk drive components. It increases the performance by replicating and dividing the data through many levels between multiple physical drives. There are 12 Raid Levels which are as follows:
- Level 0: it is a 'striped' disk array (provides data stripping) without fault tolerance.
- Level 1: It is used in system for “mirroring” and “duplexing” purpose.
- Level 2: in this error correction takes place
- Level 3: it provides byte level stripping also called as “bit-interleaved parity”
- Level 4: is used as “dedicated parity drive” and it provides block level striping
- Level 5: is “block interleaved distributed parity”
- Level 6: is “independent data disks with double parity.
- Level 0+1: is “a mirror of stripes” and used for replication and sharing of data among disks
- Level 10: is “a stripe of mirrors”. Multiple mirrors are created and then stripes over it.
- Level 7: It adds caching to Level 3 or 4.
- Level 50: implemented as striped array with fault tolerance
- RAID S: it is proprietary striped parity RAID system

21 :: Do you know what is Lock Escalation?

Lock escalation is the process of reducing the overhead of the system by converting many fine grain locks into fewer coarse grain locks. Lock escalation threshold is determined dynamically by SQL server. It doesn’t require any configuration hassles as SQL Server choose to keep lock on both row and column for the page query.

22 :: List down some advantages of SQL Stored procedure?

By using stored procedures we can reuse the code.
Stored procedure helps in reducing network traffic and latency.
Stored procedures provide better security to your data.
Stored procedure is cached in SQL Server’s memory. So it helps to reduce the server overhead. It also enhances application performance.
Stored procedures help us in the encapsulation of the code. The code of the stored procedure can be changed without affecting application.

23 :: Explain what is the difference between a Local and a Global temporary table?

Temporary tables are used to allow short term use of data in SQL Server. They are of 2 types:

Local

Only available to the current Db connection for current user and are cleared when connection is closed.

Multiple users can’t share a local temporary table.

Global

Available to any connection once created. They are cleared when the last connection is closed.

Can be shared by multiple user sessions.

24 :: Explain what are the basic functions for master, msdb, model, tempdb databases?

The Master database contains catalog and data for all databases of the SQL Server instance and it holds the engine together. Because SQL Server cannot start if the master database is not working.
The msdb database contains data of database backups, SQL Agent, DTS packages, SQL Server jobs, and log shipping.
The tempdb contains temporary objects like global and local temporary tables and stored procedures.
The model is a template database which is used for creating a new user database.

25 :: Explain what is Log Shipping?

Log shipping enables high availability of database. It the process of shipping the transaction log to another server. It copies the replica of the database. Both the databases are in synch. In case of failure of primary server or database, the secondary server can be used. In this process, another server called as monitor that tracks the history and status of backup and restore operations.
Basic SQL Server Interview Questions and Answers
Basic SQL Server Interview Questions and Answers