Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 February SQL Server 2012: Create Sequence object to generate Alphanumeric Sequence Number

SQL Server 2012: Create Sequence object to generate Alphanumeric Sequence Number

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

SQL Server 2012 introduced a Sequence object with lots of functionality, but unfortunately, we can only create Sequence Object with Number data-types.

We can create a Sequence object for a list of below data-types:

tinyint
smallint
int
bigint
decimal
numeric

But in some situations, we also require alphanumeric Sequence Number, and for that, we should apply special FORMAT on the value of Sequence Number.

Below is a full demonstration to FORMAT a Sequence value and make it alphanumeric.

First, Create sample table:

1
2
3
4
5
6
7
CREATE TABLE dbo.tbl_TestVarcharSequence
(
VarcharID VARCHAR(10)
,Name VARCHAR(255)
,CONSTRAINT pk_tbl_TestVarcharSequence_VarcharID PRIMARY KEY(VarcharID)
)
GO

Create a Sequence object:

1
2
3
4
CREATE SEQUENCE dbo.seq_TestVarcharSequenceNumber AS
INT START WITH 1
INCREMENT BY 1;
GO

Create Sequence constraint using FORMAT function:

1
2
3
4
5
ALTER TABLE dbo.tbl_TestVarcharSequence
ADD CONSTRAINT seq_tbl_TestVarcharSequence_VarcharID DEFAULT
FORMAT((NEXT VALUE FOR dbo.seq_TestVarcharSequenceNumber),'ABC000000#')
FOR VarcharID;
GO

Insert few sample records:

1
2
3
INSERT INTO dbo.tbl_TestVarcharSequence (Name)
VALUES ('Anvesh'),('Alex'),('Roy'),('Bony')
GO

The Result:

1
SELECT * FROM dbo.tbl_TestVarcharSequence

SQL Server Alphanumeric Sequence

You can find Alphanumeric Sequence Number in the above result.

Feb 3, 2016Anvesh Patel
MySQL: Create FEDERATED Table using CREATE SERVERMySQL 5.7: Introduced EXPLAIN FOR CONNECTION to check the Execution Plan of Running Connections
Comments: 1
  1. Kali
    April 12, 2016 at 8:16 am

    What’s up to every , since I am really keen of reading this weblog抯 post to be updated daily. It consists of nice material.

Anvesh Patel
Anvesh Patel

Database Engineer

February 3, 2016 SQL ServerAlphanumeric Sequence, Anvesh Patel, database, database research and development, dbrnd, Sequence object, SQL Query, SQL Server, SQL Server 2012, SQL Server Administrator, SQL Server Monitoring, SQL Server Performance Tunning, SQL Server Tips and Tricks, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....