Wednesday, 27 August 2014

SQL Server Recovery Models - Specifications and Significance!

SQL Server provides an efficient way of backing up the databases by logging all the transactions in log file but it becomes equally important to decide which data has to be backed up and which not by limiting the logging process. In this section we will discuss about the SQL Server Recovery Models and its purpose.

What SQL Are Server Recovery Models?

SQL Server has a property which controls the way transactions must be logged and its growth. This property comes under the SQL recovery models. This controls the transaction log maintenance which can be different for different databases as per its importance. It is important to choose right model as per the requirements which can be also switched if required in future. To understand these Recovery Models it is important to understand first what “Transaction Log file” is.

Transaction Log: 

SQL Server has an internal mechanism which keeps a detailed record of all the transactions made. This includes all type of database modifications recorded as a string of log records that too in a sequence of their creation. In case of any database malfunction or corruption, these transaction logs can be utilized to bring back the database in consistent state.
There are three different types of recovery models;
  1. Simple
  2. Full
  3. Bulk-Logged
        Simple SQL Recovery Model:
    
    As name suggests, this model is the simplest one amongst all the models and lets the transaction log file maintain minimal amount of information. SQL Server itself truncates the log files removing the information about transactions which have reached checkpoints (has been written to data file) to limit the space. This space once freed can be used for other entries. Hence inn case of this recovery model you should take precaution on keeping the backup interval time less so that data loss is minimized but it can affect the production work.

     Pros: This model is extremely simple to be managed and requires and performs better as minimum transaction log file space is used.

     Cons: Only recent full database or differential backups’ data is recoverable. This Model has highest risks of data loss. It will not provide; Log Shipping, Point-in-time restores, AlwaysOn or Database mirroring.

     Usage: For test environment SQL databases or some cases where data can be regenerated or restored form the data source, this model can be utilized.

        Full SQL Recovery Model 

     Full Recovery model is built to record and maintain each and every transaction made until a full backup is taken which includes everything. This model can be used as a disaster recovery strategy as it comprises full backup with along with differential backup and transaction log backups. For controlling the increasing size of transaction log, it should be backed up to make it truncated. 

     Pros: This model provides complete protection and is foremost solution to keep data available even after corruption in databases. One can recover data to any point like right before the error occurred and hence is most effective strategy. 

     Cons: Maintenance can be really tough as you will need to setup log backup ensuring the growth is in control. Taking full backup can resolve the unnecessary growth of the transaction log file. 

     Usage: Databases which are extremely crucial and you don’t want to take any chances can be formulated with Full Recovery model.

        Bulk-Logged SQL Recovery Model

     Bulk-Logged recovery model is same as Full recovery model with only difference that this model handles the bulk data modification operations like (BCP, INSERT SELECT, Index Creation, BULK INSERT, etc.) using minimal logging. Minimal logging implies that only that much information will be logged which is required to recover transaction without exhibiting any-time recovery. Processing time will be saved using this model and it will also save log space usage. This in turn restricts you from any-time-recovery option.

     Pros: Transaction log’s growth can be controlled as it will to minimal logging for bulk data. 

     Cons: Any-time-recovery option will not be available like Full Recovery model. Maintenance can be complicated.

     Usage: You can switch to bulk-logged model when bulk operations has to be done and as it is done you can switch back to full recovery model. 

      How to Will You Change Recovery Model

      There are two methods to View or Change Recovery Model;
  •          SQL Server Management Studio
  •          Using Transact – SQL
     SQL Server Management Studio:

      Steps to View or Change:
  •   Connect to apt instance of SQL Database Engine.
  •   Click Server Name in Object Explorer and expand the Server tree.
  •    Expand the Databases and right-click the database.
  •   Click Properties which in turn opens Database properties dialog box.
  •   Now in Select a Page pane click the Options.
  •   Here you will be able to see current Recovery Model in its list box.
  •    By clicking the drop-down menu you can change the Recovery Model.
  •    Once done click OK.

      Using Transact – SQL:

      Steps to View Recovery Model:

  •   Connect to Database Engine.
  •   Now, from Standard bar click New Query.
  •   Copy & Paste the below arguments to query window and click on Execute.

     Steps to Change the Recovery Model:

  •   Connect to Database Engine.
  •   Again, from Standard bar click New Query.
  •      Copy & Paste the below arguments to query window and click on Execute.

      Conclusion:

    You can choose Recovery Model for your SQL databases as per your requirements. Different Recovery Models can be chosen as per the importance of databases. For e.g. a very important database must have Full Recovery Model at the backend so that there are less chances of data loss. But it is extremely important to backup the transaction log file prior changing the Recovery Model of certain database’s transaction log file as any mistake can ultimately lose the data.

Friday, 8 August 2014

An Overview of RDBMS (Relational Database Management System) Concept

RDBMS is the basis of all SQL databases like; MS SQL Server, Sysbase, Oracle, MySQL, etc. It works on the base of a relational database model. The RDBMS stores all its data in the form of an object that is called Table. A Table consists of columns, rows, and related data entry fields.

Given below is an example of the table, consisting of 4 columns and 2 rows with the data entry fields as; ID, name, age, and address.

ID
Student Name
Age
Address
10
John
25
Brooklyn
20
Edward
24
Florida
30
Michael
23
Peru

A Table, The collection of all entities is called filling in the table. For example: fields in the above table are id, student name, age and address.

A record, in the table is each individual entry in the table.

A null value, in the table is the value that appears to be blank and a null value is different than zero value.

SQL Constraints:

SQL Constraints are used on the data columns in table. It is also limited to, use the type of data in a table which in turn ensures the reliability and accuracy of the data in the database. Constraints could be of a column or table label. The column label constraint is used only in one column and table label constraint is used in the entire table.

There are following constraints used in SQL:

NOT NULL Constraint: It is used to ensure column value is not null.
UNIQUE Constraint: It is used to ensure all values are different in a column.
DEFAULT Constraint: It is used to provide value to a column when none is specified.
INDEX: It is used to create and retrieve data from the database.
PRIMARY KEY: It is used to identify records or rows in a database table.
FOREIGN KEY: It is used to identify each record or row in a database table.
CHECK: It is used to ensure all values in the column to satisfy a certain condition.

Data Integrity:

The following data integrity exists with RDBMS:

• Entity Integrity: It ensures that there are no duplicate rows in a table.
• Domain Integrity: It ensures entries in a column by restricting its type, range of values and format.
• User Defined: It enforces some specific rules.
• Referential Integrity: It ensures row’s data, which are used by other records isn’t deleted.

Database Normalization:

Database normalization is the process to organize the data. It is used to eliminate redundant data from the database, e.g. storing same data for more than one table records and ensuring data dependencies as well. All these features reduce the spaces used in the database and make sure that data is logically stored in the database. Normalization helps to create a better data structure. There are three normalization forms used in the database.

1NF (First Normal Form): 

It is used to set basis set of rules to the database:
Defines data items in the table.
Ensures repeated data groups in the table and ensures there is a primary key.

2NF (Second Normal Form):

2NF states that all 1NF rules meet the requirement and ensures that there is no partial dependency of the column for the primary key.

3NF (Third Normal Form): 

It ensures all rules of 2NF and all non-primary fields are dependent on the primary key.

ID
Student Name
Age
Address
30
Michael
23
Peru
30
Michael
23
Ireland
30
Michael
23
USA

According to the 1NF rule, the repeated groups will be divided into two parts or table:

ID
Student Name
Age
30
Michael
23

Set primary key on the second table, then the result would be:
Note: Primary is applied on both the above tables.

Primary_ID
Student ID
Address
1
30
Peru
2
30
Ireland
3
30
USA

Conclusion:

I have explained briefly about the RDBMS on SQL Server, there data storage, table creation with entries and records, SQL constraints, data integrity to ensure how data is carried out and managed, database normalization for organizing data structure and their accuracy to bring out the database in a well organized manner. Further, I will also be explaining more details about RDBMS.

Friday, 1 August 2014

Basic Information About SQL Server Versions 2005 to 2014

Nowadays,it’s true to say that Information Technology has changed the world so far and related technologies have given their best contribution in the respective field. In the same way, SQL Server is one among them; used by organizations to maintain their largesized databases in a regular, safe and specified way. Microsoft SQL Server is a Relational Database Management System (RDBMS) developed by Microsoft. It is an application to create and store data as requested by other application software’s like SSMS. It uses two query languages, i.e. T-SQL and ANSI SQL. It also uses DML (Data Manipulation Language) and DDL (Data Definition Languages) languages.

SQL Server holds its database in Primary and Secondary databases. For Primary database, an MDF file is created while, for Secondary database; an NDF file is created to store its data. An LDF file is one that holds transaction log entries.

Followed are the SQL Server versions that came into the market till date; 2000, 2005, 2008, 2008 R2, 2012 and 2014. At the very beginning, SQL Server version 2000 had added several performance measures like SSIS (SQL Server Integration Services), reporting server, data mining server and messaging related technologies.You can find a brief introduction and description of all the SQL Server versions currently available.

SQL Server 2005:

This version was released on October 2005. It supports XML data types. CLR (Common Language Runtime) was introduced through this version of SQL Server. It allows databases to be exposed to the web services by using TDS. The code for this version of SQL is managed by, CLR. In this version, T-SQL was added to the error handling features and support for recursive queries. This Server version was introduced with better error recovery systems, indexing algorithms, syntax and optimistic concurrency added, for better performance. It uses a method, namely; “MARS (Multiple Access Result Sets)” for database connection to be established with multiple users. It also introduced DMVs (Dynamic Management Views) for monitoring the Server instance; problems and performance.

SQL Server 2008:

This version was released on August 6,2008 introducing a technology like AlwaysOn. This version of SQL Server,particularly focused on data management performance. Support for structured and semi-structured data, including digital media formats like; audio, video, etc. was provided in this version of SQL. These multimedia data files were stored as BLOBs (Binary Large Objects). It supported all data types like; XML, emails, documents, files and performed searches, analysis, sharing and synchronization. It came with better compression features which helped in improving scalability. It has enhanced indexing algorithms, capabilities for providing transparent data encryption, and compression of backups too. It also supports facilities like; Windows PowerShell and Cmdlets.

SQL Server 2008 R2:

This version was released on April 21, 2010. It added Master Data Services to SQL Server. It was made possible to manage multiple SQL Server 2008 instances by using this version that also provided services like; relational databases, analysis services, reporting services, and integration services. It came with two different service pack versions; 1 and 2.

SQL Server 2012:

This version of SQL Server was released on March 06, 2012. It also came with two service packs 1 and 2 like the previous version. It offers support for OLE DB, AlwaysOn SQL Server Failover Cluster Instances, and Availability Groups. It introduced some new features like the new DMVs and functions, new programmability, Meta data discovery, THROW statements, performance enhancement, security enhancement,schema assignments, etc.

SQL Server 2014:

This version was released on the 1st of April, 2014. It provides in-memory capabilities for tables that can fully fit in the memory. It provides SSD Buffer Pool extension for disk based SQL Server applications that help improve performance between DRAM and spinning media. It also enhances AlwaysOn property and new hybrid disaster recovery along with backup solutions.

Conclusion

With the growing dependency ratio of enterprises on SQL Server; the gradual release of new versions was observed on a quite frequent note in the recent past. The release of SQL Server version 2014 is the latest in time and also the finest till date; offering enhanced properties and option. Technology has always taken aback users by rapidly increasing in terms of advancement and adaptability, and the same applies to SQL Server version updates witnessed till present.