Basic SQL Server

  Home  MS SQL Server  Basic SQL Server


“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

81⟩ Please explain GO Command in SQL Server?

GO command indicates the end of the SQL statements. It is used when there are multiple statements to be executed but sent as a batch.

Example:

SELECT * FROM table1 INNER JOIN table2 ON table1.c1 = table2.c1 WHERE table1.c1 > 10 ORDER BY table1.c1

GO

 184 views

82⟩ Do you know what are ACID properties of Transaction?

Following are the ACID properties for Database.

Atomicity – Transactions may be set of SQL statements. If any of statement fails then the entire transaction fails. The transaction follows all or nothing rule.

Consistency – This property says that the transaction should be always in consistent state. If any transaction is going to effect the database’s consistent state then the transaction could be rolled back.

Isolation – This property says that one transaction can not retrive the data that has been modified by any other transaction until its completed.

Durability – When any transaction is committed then it must be persisted. In the case of failure only committed transaction will be recovered and uncommitted transaction will be rolled back.

 183 views

83⟩ Tell me what is the significance of NULL value and why should we avoid permitting null values?

NULL value means that no entry has been made into the column. It states that the corresponding value is either unknown or undefined. It is different from zero or "". They should be avoided to avoid the complexity in select & update queries and also because columns which have constraints like primary or foreign key constraints cannot contain a NULL value.

 222 views

84⟩ Can you explain what are COMMIT and ROLLBACK in SQL?

COMMIT statement is used to end the current transaction and once the COMMIT statement is exceucted the transaction will be permanent and undone.

Syntax: COMMIT;

Example:

BEGIN

UPDATE EmpDetails SET EmpName = ‘Arpit’ where Dept = ‘Developer’

COMMIT;

END;

ROLLBACK statement is used to end the current transaction and undone the changes which was made by that transaction.

Syntax: ROLLBACK [TO] Savepoint_name;

Example

BEGIN

Statement1;

SAVEPOINT mysavepoint;

BEGIN

Statement2;

EXCEPTION

WHEN OTHERS THEN

ROLLBACK TO mysavepoint;

Statement5;

END;

END;

 190 views

85⟩ Explain what is the difference between UNION and UNION ALL?

UNION selects only distinct values whereas UNION ALL selects all values and not just distinct ones.

UNION: SELECT column_names FROM table_name1

UNION

SELECT column_names FROM table_name2

UNION All: SELECT column_names FROM table_name1

UNION ALL

SELECT column_names FROM table_name2

 205 views

86⟩ Tell me what is a Linked Server?

When we want to query on remote database server along with the local database server then we can add the remote SQL server to local SQL server in a same group using the concept called Linked Server.

We can query on both servers using T-SQL.

We can use stored Procedure sp_addlinkedserver, sp_addlinkedsrvlogin to add new Linked Server.

By using Linked Server we can SQL statement in clean and easy way to retrieve, join and combine remote data with local data.

 176 views

87⟩ Explain what is use of DBCC Commands?

DBCC (Database consistency checker) act as Database console commands for SQL Server to check database consistency. They are grouped as: Maintenance: Maintenance tasks on Db, filegroup, index etc. Commands include DBCC CLEANTABLE, DBCC INDEXDEFRAG, DBCC DBREINDEX, DBCC SHRINKDATABASE, DBCC DROPCLEANBUFFERS, DBCC SHRINKFILE, DBCC FREEPROCCACHE, and DBCC UPDATEUSAGE.

Miscellaneous: Tasks such as enabling tracing, removing dll from memory. Commands include DBCC dllname, DBCC HELP, DBCC FREESESSIONCACHE, DBCC TRACEOFF, DBCC FREESYSTEMCACHE, and DBCC TRACEON. Informational: Tasks which gather and display various types of information. Commands include DBCC INPUTBUFFER, DBCC SHOWCONTIG, DBCC OPENTRAN, DBCC SQLPERF, DBCC OUTPUTBUFFER, DBCC TRACESTATUS, DBCC PROCCACHE, DBCC USEROPTIONS, and DBCC SHOW_STATISTICS.

Validation: Operations for validating on Db, index, table etc. Commands include DBCC CHECKALLOC, DBCC CHECKFILEGROUP, DBCC CHECKCATALOG, DBCC CHECKIDENT, DBCC CHECKCONSTRAINTS, DBCC CHECKTABLE, and DBCC CHECKDB.

 192 views

88⟩ Do you know what is a WITH(NOLOCK)?

WITH(NOLOCK) is used to unlock the data which is locked by the transaction that is not yet committed. This command is used before SELECT statement.

When the transaction is committed or rolled back then there is no need to use NOLOCK function because the data is already released by the committed transaction.

Syntax: WITH(NOLOCK)

Example:

SELECT * FROM EmpDetails WITH(NOLOCK)

WITH(NOLCOK) is similar as READ UNCOMMITTED

 181 views

89⟩ 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.

 167 views

90⟩ 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.

 191 views

91⟩ 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.

 178 views

92⟩ 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.

 192 views

93⟩ 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.

 169 views

94⟩ 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

 186 views

95⟩ 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.

 180 views

97⟩ 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.

 177 views

98⟩ 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.

 163 views

99⟩ 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.

 178 views

100⟩ 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.

 183 views