Skip to main content

SQL Server 2012: Nice features for developers

I finally found some time to have a look at SQL Server 2012. There is still a lot to discover but I already want to highlight 2 great new features:
Sequence Objects

It’s a feature I already know from Oracle, but now SQL Server finally supports Sequence Objects too. A sequence object generates sequence of unique numeric values. It’s a nice alternative if you don’t want to use Identity fields or want to get a unique number up front.

Here is a sample that creates a sequence that starts with 1 and gets incremented by 1. The minimum value is 0 and maximum value is 100. If you go higher that 100 an error is thrown(if you don’t want this you can change this by specifying ‘cycle’ instead of  ‘no cycle’.

create sequence SampleSequence as int
start with 1 -- Start with value 1
increment by 1-- Increment with value 1
minvalue 0 -- Minimum value to start is zero
maxvalue 100 -- Maximum it can go to 100
no cycle -- Do not go above 100
cache 50 -- Increment 50 values in memory rather than incrementing from IO

To increment the value we need to call the statement below:

SELECT NEXT VALUE FOR dbo.SampleSequence AS seq_no;
Pagination

Another nice features that got added to SQL Server 2012 is the built-in support for pagination. Before I had to combine “ROW_NUMBER and “TOP” to get a subset of results. Now I can use  “OFFSET” and “FETCH’ commands to do pagination.

To skip the first 10 results and take the next 10 results from a Products table, I can write the following query:

SELECT * FROM PRODUCTS
ORDER BY PRODUCTNAME
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY

Popular posts from this blog

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

.NET 9 - Goodbye sln!

Although the csproj file evolved and simplified a lot over time, the Visual Studio solution file (.sln) remained an ugly file format full of magic GUIDs. With the latest .NET 9 SDK(9.0.200), we finally got an alternative; a new XML-based solution file(.slnx) got introduced in preview. So say goodbye to this ugly sln file: And meet his better looking slnx brother instead: To use this feature we first have to enable it: Go to Tools -> Options -> Environment -> Preview Features Check the checkbox next to Use Solution File Persistence Model Now we can migrate an existing sln file to slnx using the following command: dotnet sln migrate AICalculator.sln .slnx file D:\Projects\Test\AICalculator\AICalculator.slnx generated. Or create a new Visual Studio solution using the slnx format: dotnet new sln --format slnx The template "Solution File" was created successfully. The new format is not yet recognized by VSCode but it does work in Jetbr...