Introduction
SQL Server 2014 provides memory-optimized database technologies for optimizing performance with OLTP workloads. Particularly, this presents memory-optimized tables regarding effective, contention-free data accessibility, as well as natively created Stored Procedures for efficient execution of business logic.
For enabling the database for In-Memory OLTP you require a database. Let's create a database. If you have an existing database then skip this step.
Create Database
CREATE DATABASE sharad
GO
If you want to create a database with SSMS then use the following procedure:
- In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance.

- Right-click "Databases", click "New Database" and then enter the value for the database name.


Enable your database for In-Memory OLTP
We're going to provide a filegroup regarding "memory_optimized_data" to the database, along with a container to this filegroup. This kind of filegroup will probably be used to assure durability of memory-resident data in the event of a new server crash as well as restart. During the crash recovery phase in server startup, the data can be restored using this filegroup and loaded back into memory space.
When creating your container inside the memory_optimized_data filegroup you will need to specify your storage location. During this example we have a tendency to pick the folder "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\imoltp_mod1". confirm the folder exists before running the script.
You can enable In-Memory OLTP by executing the following query.
First Query
ALTER DATABASE sharad ADD FILEGROUP imoltp_mod CONTAINS MEMORY_OPTIMIZED_DATA
GO
After executing the First Query, execute the second query given below.
Second Query
ALTER DATABASE sharad ADD FILE (name='imoltp_mod1', filename='C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\imoltp_mod1') TO FILEGROUP imoltp_mod
GO
And if you want to enable your database for In-Memory OLTP with SSMS then
add a memory_optimized_data filegroup and its container as in the following:
-
In Object Explorer, expand the "Databases" node, right-click your database and then click "Properties".

-
To add a new memory optimized data filegroup, click the Filegroups page. Under MEMORY OPTIMIZED DATA, click "Add filegroup" and then enter the values for the filegroup.

-
To add a file to the filegroup, click the General page. Under Database files, click "Add" and then enter the values for the file. Use file type FILESTREAM Data.

Create your first memory-optimized table
We are currently able to produce our own very first memory-optimized tables. We now have the following two tables, "test", in addition to "UserSession". "test" is a durable table (the default), that implies that its contents are persisted on disk and cannot be lost on a server crash. "UserSession" is a non-durable table (DURABILITY=SCHEMA_ONLY), meaning that the particular contents with the table can be found simply within memory, and therefore are lost on server restart.
Observe that throughout CTP1 memory-optimized tables support solely "nonclustered hash" indexes.
Create memory optimized table using query
For table "test":
USE sharad
GO
CREATE TABLE test (
Id int not null primary key nonclustered hash with (bucket_count=2000000),
Name varchar(100),
Salary varchar(100)
)
WITH (MEMORY_OPTIMIZED=ON)
GO
For table "UserSession":
CREATE TABLE UserSession (
SessionId int not null primary key nonclustered hash with (bucket_count=400000),
Id int not null,
index ix_Id nonclustered hash (Id) with (bucket_count=400000)



SubashPosted Sep 7, 2016, 2:26 AM
Nice one
Anil KumarPosted Jul 14, 2013, 2:33 PM
interesting