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: Msg 11730, Database name cannot be specified for the sequence object in default constraints

SQL Server 2012: Msg 11730, Database name cannot be specified for the sequence object in default constraints

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

In this post, I am sharing the solution to use a single Sequence object between different databases.

We are creating a sequence constraint to assign a sequence object to a particular table, which both are on the same database.

Sometimes, we also require using a Sequence object of an another database.
Unfortunately, you cannot specify another database name when you are creating a default sequence object.

Below is a full demonstration on this:

Create a Sequence object:

1
2
3
4
5
6
7
USE [AdventureWorks2012]
GO
 
CREATE SEQUENCE dbo.seq_TestSequenceNumber AS
INT START WITH 1
INCREMENT BY 1;
GO

I created this sequence into AdventureWorks2012 database.

Now use this created Sequence object into TempDB:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
USE tempdb
GO
 
CREATE TABLE dbo.tbl_TestSequence
(
ID INT
,Name VARCHAR(255)
,CONSTRAINT pk_tbl_TestSequence_ID PRIMARY KEY(ID)
)
GO
 
ALTER TABLE dbo.tbl_TestSequence
ADD CONSTRAINT seq_tbl_TestSequence_ID DEFAULT
NEXT VALUE FOR [AdventureWorks2012].[dbo].[seq_TestSequenceNumber]
FOR ID;
GO

You will get this error message:

SQL Server Sequence Database Name Error

The solution is to use Sequence object with INSERT statement:

1
2
3
4
5
6
7
8
9
USE tempdb
GO
 
INSERT INTO dbo.tbl_TestSequence
VALUES
(NEXT VALUE FOR [AdventureWorks2012].[dbo].[seq_TestSequenceNumber],'Anvesh')
,(NEXT VALUE FOR [AdventureWorks2012].[dbo].[seq_TestSequenceNumber],'Neevan')
,(NEXT VALUE FOR [AdventureWorks2012].[dbo].[seq_TestSequenceNumber],'Roy')
GO

The Result:

SQL Server Sequence Database Error Result

Feb 13, 2016Anvesh Patel
SQL Server: Difference between Temporary Table and Table VariablePostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)
Anvesh Patel
Anvesh Patel

Database Engineer

February 13, 2016 SQL ServerAnvesh Patel, database, database research and development, dbrnd, sequence, 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....