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