Saturday, September 15, 2018

Interview Questions and Answers - 2


What is the recovery model? List the types of recovery model available in SQL Server?

Ans. Recovery model basically tells SQL Server what data should be kept in the transaction log file and for how long. A database can have only one recovery model.
It also tells SQL server that which backup is possible in a particular recovery model selected. There are three types of recovery model:
·         Full
·         Simple
·         Bulk-Logged

What are the types of backups available in SQL Server?

Ans. Different possible backups are:
·         Full backup
·         Differential Backup
·         Transaction Log Backup
·         Copy Only Backup
·         File and File group backup

What is Mirroring? What are the advantages of the Mirroring?

Ans. Mirroring is a high availability solution. It is designed to maintain a hot standby server which is consistent with the primary server in terms of a transaction. Transaction Log records are sent directly from principal server to secondary server which keeps a secondary server up to date with the principal server.

Advantages of Mirroring are:
·         It is more robust and efficient that Log shipping.
·         It has an automatic failover mechanism.
·         The secondary server is synced with the primary in near real time.

Which TCL Commands are available on the SQL Server?

Ans.  There are 3 TCL Commands in the SQL Server. These are as follows:
Commit: This command is used to save the transaction permanently in the database.
Rollback: This is used to roll back the changes that are done i.e. to restore the database in the last committed state.
Save Tran: This is used for saving the transaction so as to provide the convenience that the transaction can be rolled back to the point wherever required.

What is the difference between a Local and a Global temporary table?

Ans. If defined in inside a compound statement a local temporary table exists only for the duration of that statement but a global temporary table exists permanently in the database but its rows disappear when the connection is closed.


Interview Question and Answers - 1


1. Difference between TRUNCATE and DELETE
                - Truncate is DDL command so can't be rolled back while Delete is a DML                               command so it can.
                - Truncate keeps the lock on table while Delete keeps the lock on each row.
                - Truncate resets the counter of the Identity column while Delete doesn't do so.
                - Truncate does not fire trigger but Delete fires trigger.
                -Truncate removes all rows by de allocating data pages allocated to the table                      while Delete removes rows one by one.
2.  What are the advantages a stored procedure?
                Stored Procedures are pre compiled and stored in the database. This enables the database to    execute the queries much faster. Since many queries can be included in a stored procedure,  round trip time to execute multiple queries from source code to database and back is   avoided.
3.  What are the advantages and disadvantages of views in a database?
   Advantages:
·             Views don't store data in a physical location.
·             The view can be used to hide some of the columns from the table.
·             Views can provide Access Restriction, since data insertion, update and deletion is not    possible with the view.
Disadvantages:
·             When a table is dropped, associated view become irrelevant.
·             Since the view is created when a query requesting data from view is triggered, its a bit slow.
·         When views are created for large tables, it occupies more memory.
4. What  is the ACID property?
·             ACID (Atomicity Consistency Isolation Durability
·             Atomicity is an all-or-none rule for database modifications.
·             Consistency guarantees that a transaction never leaves your database in a half-finished state.
·             Isolation keeps transactions separated from each other until they are finished.
·             Durability guarantees that the database will keep track of pending changes in such a way that the server can recover from an abnormal termination and committed transactions will not be lost.
5. What are the different types of triggers?
  There are three types of triggers
·         DML trigger
              There are two kinds of DML triggers
                a. Instead of Trigger
                     Instead of Triggers are fired in place of the triggering action such as an                             insert, update, or delete.
                b. After Trigger
                    After triggers execute following the triggering action, such as an insert,                            update, or delete.
·         DDL trigger
                  This type of trigger is fired against DDL statements like Drop Table, Create                        Table, or Alter Table. DDL Triggers are always after Triggers.
·         Logon trigger
                  This type of trigger is fired against a LOGON event before a user session is                         established to the SQL Server.