Solved

Find name of SQL Sequence

Posted on 2011-03-24
3
421 Views
Last Modified: 2012-05-11
I'm currently trying to write an insert query for a db and want to get the next value from a sequence for one of the insert fields.
The only problem is I don't know what the sequence is called! I can query the table and see the sequences in there but I cant find out the actual name of the sequence??

If anyone could help that would be great

 Screenshot
0
Comment
Question by:Gaz124
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35205848
actually, the Sequences here are are not "system" of SQL Server, like the identity field would be.
so, there is no way to know which sequence would go into which table unless the relation sequence-table is stored somewhere.
it is hence only used in application code, so you cannot know it from that data you showed.

question: why use such a sequence object if you could use IDENTITY?
0
 
LVL 7

Expert Comment

by:mkobrin
ID: 35205850
After the insert statement select the @@Identity field eg:

insert into a (a,b,c) values (1,2,3)
select @@identity as newID

will insert the record and return the new id in a field called newID
0
 

Author Comment

by:Gaz124
ID: 35206029
Thanks angellll, at least I know im not going nuts now. I'll  contact the application writers.

mkobrin - I think you misunderstood the question
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now