This article is half-done without your Comment! *** Please share your thoughts via Comment ***
I didn’t explore few features of SQL Server 2014. Recently, I got to know that in SQL Server 2014 we can create indexes on Table Variable.
If you look into the differences between Temp Table and Table Variable, always you can find one difference like we can’t create an index on Table Variable and we can create an index on the Temp Table.
SQL Server: Difference between Temporary Table and Table Variable
In this post, I am sharing few examples of Table variable with Indexes.
Please check the below samples:
Define Table variable with Primary key and Unique key:
1 2 3 4 5 |
DECLARE @dbrnd TABLE ( ID INT PRIMARY KEY ,Name NVARCHAR(10) UNIQUE ) |
Define Table variable with Non-Clustered index:
1 2 3 4 5 6 |
DECLARE @dbrnd TABLE ( ID INT PRIMARY KEY ,Name NVARCHAR(20) ,INDEX idx_dbrnd_Name NONCLUSTERED (Name) ) |
Leave a Reply