Monday, June 6, 2016

use Sequences in SQL Server

//sequences used in version(12) Example
CREATE TABLE dbo.Contacts (
        ContactId int IDENTITY(1,1) NOT NULL,
        FirstName varchar(60),
        LastName varchar(60),
        Phone varchar(60)
);

INSERT INTO dbo.Contacts
SELECT name, name, name
FROM master.dbo.spt_values;

-- Skip 300 rows 'into' the results and
-- take the next 10 records:
SELECT ContactId, FirstName, LastName, Phone
FROM dbo.Contacts
ORDER BY ContactId
        OFFSET 0 ROWS
        FETCH NEXT 10 ROWS ONLY;



No comments: