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.
sybase-ase
add a comment |
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.
sybase-ase
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 usedMAX()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
add a comment |
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.
sybase-ase
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
sybase-ase
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 usedMAX()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
add a comment |
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 usedMAX()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
add a comment |
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.
Thanks Rob! When i doSELECT next_identity('tablename')it returns (NULL) also when i try to CAST it to int it returnsNULLAny 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
add a comment |
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.
Thanks Rob! When i doSELECT next_identity('tablename')it returns (NULL) also when i try to CAST it to int it returnsNULLAny 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
add a comment |
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.
Thanks Rob! When i doSELECT next_identity('tablename')it returns (NULL) also when i try to CAST it to int it returnsNULLAny 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
add a comment |
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.
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.
answered Nov 9 at 7:34
RobV
1,877155
1,877155
Thanks Rob! When i doSELECT next_identity('tablename')it returns (NULL) also when i try to CAST it to int it returnsNULLAny 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
add a comment |
Thanks Rob! When i doSELECT next_identity('tablename')it returns (NULL) also when i try to CAST it to int it returnsNULLAny 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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