About Me

My photo
Mumbai, Maharastra, India
He has more than 7.6 years of experience in the software development. He has spent most of the times in web/desktop application development. He has sound knowledge in various database concepts. You can reach him at viki.keshari@gmail.com https://www.linkedin.com/in/vikrammahapatra/ https://twitter.com/VikramMahapatra http://www.facebook.com/viki.keshari

Search This Blog

Tuesday, December 9, 2014

Cannot create default constraint with sequence object on global temporary table


I was toying with SQL sequence object and all of sudden I was surprise to find that we cannot create default constraint with sequence object on Global temporary table. Let me demonstrate my finding with an example.

Here we are creating a global temporary table with two fields

create table ##temoAddSequence
(id int,
name varchar(20))
Command(s) completed successfully.

Lets insert few records in it.

insert into ##temoAddSequence values(2,'Amrapali')
insert into ##temoAddSequence values(5,'Mahin')

lets create a sequence object

create sequence seq_IdCounter
as int
       minvalue 1
       no maxvalue
       start with 4
       increment by 1
       ;
go
Command(s) completed successfully.

Lets try to associate this sequence object to Id column of ##temoAddSequence table

alter table ##temoAddSequence
add constraint id_default_sequence
default (next value for seq_Counter) for id;
Msg 208, Level 16, State 1, Line 19
Invalid object name 'seq_Counter'.

Conclusion: We cannot create default constraint with sequence object on Global temporary table.

When you are on my head SQL, I abscond from all tasks, to shower my love to you  :)


Post Reference: Vikram Aristocratic Elfin Share

No comments:

Post a Comment