Get next value of AUTO INCREMENT











up vote
-1
down vote

favorite












How do i determine what the next value is of the Primary Key Auto increment?



I have been looking in the system databases but i couldnt find any answers.










share|improve this question
























  • Select and Order by that column, descending, limit 1, then add one to the result?
    – cricket_007
    Nov 8 at 5:01










  • That is exactly what i have done, i used MAX() function. Does the index from the primary key also change after this?
    – Wvs
    Nov 8 at 14:16










  • I don't know Sybase, but no values of any technology should be changing as part of a read/select operation
    – cricket_007
    Nov 8 at 15:04















up vote
-1
down vote

favorite












How do i determine what the next value is of the Primary Key Auto increment?



I have been looking in the system databases but i couldnt find any answers.










share|improve this question
























  • Select and Order by that column, descending, limit 1, then add one to the result?
    – cricket_007
    Nov 8 at 5:01










  • That is exactly what i have done, i used MAX() function. Does the index from the primary key also change after this?
    – Wvs
    Nov 8 at 14:16










  • I don't know Sybase, but no values of any technology should be changing as part of a read/select operation
    – cricket_007
    Nov 8 at 15:04













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











How do i determine what the next value is of the Primary Key Auto increment?



I have been looking in the system databases but i couldnt find any answers.










share|improve this question















How do i determine what the next value is of the Primary Key Auto increment?



I have been looking in the system databases but i couldnt find any answers.







sybase-ase






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 5:01









cricket_007

77.6k1142107




77.6k1142107










asked Nov 8 at 4:54









Wvs

185




185












  • Select and Order by that column, descending, limit 1, then add one to the result?
    – cricket_007
    Nov 8 at 5:01










  • That is exactly what i have done, i used MAX() function. Does the index from the primary key also change after this?
    – Wvs
    Nov 8 at 14:16










  • I don't know Sybase, but no values of any technology should be changing as part of a read/select operation
    – cricket_007
    Nov 8 at 15:04


















  • Select and Order by that column, descending, limit 1, then add one to the result?
    – cricket_007
    Nov 8 at 5:01










  • That is exactly what i have done, i used MAX() function. Does the index from the primary key also change after this?
    – Wvs
    Nov 8 at 14:16










  • I don't know Sybase, but no values of any technology should be changing as part of a read/select operation
    – cricket_007
    Nov 8 at 15:04
















Select and Order by that column, descending, limit 1, then add one to the result?
– cricket_007
Nov 8 at 5:01




Select and Order by that column, descending, limit 1, then add one to the result?
– cricket_007
Nov 8 at 5:01












That is exactly what i have done, i used MAX() function. Does the index from the primary key also change after this?
– Wvs
Nov 8 at 14:16




That is exactly what i have done, i used MAX() function. Does the index from the primary key also change after this?
– Wvs
Nov 8 at 14:16












I don't know Sybase, but no values of any technology should be changing as part of a read/select operation
– cricket_007
Nov 8 at 15:04




I don't know Sybase, but no values of any technology should be changing as part of a read/select operation
– cricket_007
Nov 8 at 15:04












1 Answer
1






active

oldest

votes

















up vote
1
down vote













I am guessing you mean "the next value to be assigned to an identity column", and your identity column also happens to be used as a primary key. Otherwise, there is no concept in Sybase ASE that would qualify as "Primary Key Auto increment".



Assuming the above, you can get the next value to be assigned by using the function next_identity('table_name'). Note that the result is in varchar format so you may need to convert it back to a number.






share|improve this answer





















  • Thanks Rob! When i do SELECT next_identity('tablename') it returns (NULL) also when i try to CAST it to int it returns NULL Any ideas?
    – Wvs
    Nov 9 at 14:07










  • That means your table does not actually have an identity column. Check with sp_help.
    – RobV
    Nov 11 at 10:38











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201754%2fget-next-value-of-auto-increment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













I am guessing you mean "the next value to be assigned to an identity column", and your identity column also happens to be used as a primary key. Otherwise, there is no concept in Sybase ASE that would qualify as "Primary Key Auto increment".



Assuming the above, you can get the next value to be assigned by using the function next_identity('table_name'). Note that the result is in varchar format so you may need to convert it back to a number.






share|improve this answer





















  • Thanks Rob! When i do SELECT next_identity('tablename') it returns (NULL) also when i try to CAST it to int it returns NULL Any ideas?
    – Wvs
    Nov 9 at 14:07










  • That means your table does not actually have an identity column. Check with sp_help.
    – RobV
    Nov 11 at 10:38















up vote
1
down vote













I am guessing you mean "the next value to be assigned to an identity column", and your identity column also happens to be used as a primary key. Otherwise, there is no concept in Sybase ASE that would qualify as "Primary Key Auto increment".



Assuming the above, you can get the next value to be assigned by using the function next_identity('table_name'). Note that the result is in varchar format so you may need to convert it back to a number.






share|improve this answer





















  • Thanks Rob! When i do SELECT next_identity('tablename') it returns (NULL) also when i try to CAST it to int it returns NULL Any ideas?
    – Wvs
    Nov 9 at 14:07










  • That means your table does not actually have an identity column. Check with sp_help.
    – RobV
    Nov 11 at 10:38













up vote
1
down vote










up vote
1
down vote









I am guessing you mean "the next value to be assigned to an identity column", and your identity column also happens to be used as a primary key. Otherwise, there is no concept in Sybase ASE that would qualify as "Primary Key Auto increment".



Assuming the above, you can get the next value to be assigned by using the function next_identity('table_name'). Note that the result is in varchar format so you may need to convert it back to a number.






share|improve this answer












I am guessing you mean "the next value to be assigned to an identity column", and your identity column also happens to be used as a primary key. Otherwise, there is no concept in Sybase ASE that would qualify as "Primary Key Auto increment".



Assuming the above, you can get the next value to be assigned by using the function next_identity('table_name'). Note that the result is in varchar format so you may need to convert it back to a number.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 7:34









RobV

1,877155




1,877155












  • Thanks Rob! When i do SELECT next_identity('tablename') it returns (NULL) also when i try to CAST it to int it returns NULL Any ideas?
    – Wvs
    Nov 9 at 14:07










  • That means your table does not actually have an identity column. Check with sp_help.
    – RobV
    Nov 11 at 10:38


















  • Thanks Rob! When i do SELECT next_identity('tablename') it returns (NULL) also when i try to CAST it to int it returns NULL Any ideas?
    – Wvs
    Nov 9 at 14:07










  • That means your table does not actually have an identity column. Check with sp_help.
    – RobV
    Nov 11 at 10:38
















Thanks Rob! When i do SELECT next_identity('tablename') it returns (NULL) also when i try to CAST it to int it returns NULL Any ideas?
– Wvs
Nov 9 at 14:07




Thanks Rob! When i do SELECT next_identity('tablename') it returns (NULL) also when i try to CAST it to int it returns NULL Any ideas?
– Wvs
Nov 9 at 14:07












That means your table does not actually have an identity column. Check with sp_help.
– RobV
Nov 11 at 10:38




That means your table does not actually have an identity column. Check with sp_help.
– RobV
Nov 11 at 10:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201754%2fget-next-value-of-auto-increment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings