Please enable Javascript to correctly display the contents on Dot Net Tricks!
 
Ready to master C#, .NET, MVC, JAVA, PHP, AngularJS, Hadoop, Android, iphone, Testing skills?
Join our online/offline training programs and take your career to the next level! For more details call us +91-9871749695 or write us [email protected]

SQL Server 2012 New Features and Programmability Enhancements

Posted By : Shailendra Chauhan, 02 Oct 2012
Updated On : 29 Aug 2013
Total Views : 5,652   
Version Support : SQL Server 2012
 
Keywords : sql server 2012 new features,new features of sql server 2012,sql server 2012 new features and functions,sql server 2012 features enhancements, t-sql enhancements

SQL Server 2012 has a powerful set of fetures to increase productivity of developers and database administrators. SQL Server 2012 has a new SSMS that is built on Visual Studio 2010 and support various productivity features of Visual Studio 2010 like multi monitor support and pull out the tabs from main work area to different monitor or out side the IDE. Now, you can also use Visual Studio short-cut keys with SQL Server 2012. More over SQL Server 2012 supports business intellisense and debugging like Visual Studio 2010.

SQL Server 2012 Programmability Enhancements

SQL Server 2012 supports a great programmability enhancements and functions that developers and database adminsitrators will enjoy. Some new programmability enhancements and functions are listed below:

  1. T-SQL THROW Statement

  2. Now SQL Server 2012 has improved error handling by introducing throw statement for throwing exception in T-SQL. However this statement has some limitations and does not provide powerful features like RAISERROR.

  3. Conversion Functions

  4. SQL Serve 2012 has support for new conversion functions TRY_CONVERT, and TRY_PARSE for convering numeric, date, and time values to desired format. These functions are very helpful while programming T-SQL.

  5. T-SQL built-in pagination

  6. SQL Server 2012 also supports built-in pagination with the help of OFFSET and FETCH like MySQL. Actually, OFFSET and FETCH will act as a replacement for TOP in SQL Server.

     --Suppose Employee tables has 500 records
    --Below query skip 200 rows and fetch the next 20 records
    SELECT EmpID, EmpName, Salary FROM dbo.Employee
    ORDER BY EmpID
    OFFSET 200 ROWS
    FETCH NEXT 20 ROWS ONLY 
  7. T-SQL Sequence

  8. SQL Server 2012 also supports sequence like Oracle database. It works like as IDENTITY field without being a field. The main advantage of sequence is that you can use it in the same way as GUIDs and with better performance than GUIDs when used as a clustered index key.

     --Create Sequence object
    CREATE SEQUENCE objSequence
    START WITH 1
    INCREMENT BY 1;
     --Create Employee object
    DECLARE @Employee TABLE
    (
    ID int NOT NULL PRIMARY KEY,
    FullName nvarchar(100) NOT NULL
    )
     --Insert values
    INSERT @Employee (ID, FullName)
    VALUES (NEXT VALUE FOR objSequence, 'Mohan'),
    (NEXT VALUE FOR objSequence, 'Deepak'),
    (NEXT VALUE FOR objSequence, 'Pavan');
     --Show data
    SELECT * FROM @Employee 
  9. Metadata Discovery Enhancements

    SQL Server 2012 also has improved metadata discovery, which allow you to determine the shape of projected output from queries, tables, stored procedure, views, and other objects. As a result SQL Server supports business intellisense and debugging.

  10. T-SQL Format() Function

  11. SQL Server 2012 introduces a new function format() for formatting string data like as C#. It is a CLR based function.

     SELECT FORMAT(GETDATE(), 'yyyy-MM-dd') AS [ISO Formatted Date], FORMAT(GETDATE(), 'yyyy-MM-dd hh:mm:ss') AS [Full ISO], FORMAT(GETDATE(), 'MMMM dd, yyyy') AS [Long-EN Date], FORMAT(22.7, 'C', 'en-US') AS [US Currency], FORMAT(99 * 2.226, '000.000') AS [Padded Decimal], FORMAT(12345678, '0,0') AS [Commas in Large Numbers] 
What do you think?

I hope you will enjoy these tricks while programming with SQL Server. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

 
 
About the Author
Hey! I'm Shailendra Chauhan full-time author, consultant & trainer. I have more than 6 years of hand over Microsoft .NET technologies and other web technologies. I am the founder & chief editor of www.dotnet-tricks.com and www.webgeekschool.com. I am author of books ASP.NET MVC Interview Questions and Answers & AngularJS Interview Questions and Answers & LINQ Interview Questions and Answers.
I love to work with web applications and mobile apps using Microsoft technology including ASP.NET, MVC, C#, SQL Server, WCF, Web API, Entity Framework,Cloud Computing, Windows Azure, jQuery, jQuery Mobile, Knockout.js, Angular.js and many more web technologies. More...
 
Free Interview Books
 
Browse By Category
Learn In Hindi
 
 
Like us on Facebook