problem with primary key
-
Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond
-
Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond
And what does it has to do with ASP.Net?
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond
-
after the Insert query fire Select scope_identity() This will return the last inserted identity
Regards Aman Bhullar www.arlivesupport.com[^]
check this explaination out. very nice. http://davidhayden.com/blog/dave/archive/2006/01/17/2736.aspx[^]
-
Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond
If you are executing your INSERT command in a stored procedure, you can assign ID value of the inserted data to a local variable. Example: declare @returnID -- here goes your insert statement set @return = @@identity With this you have the value of the ID in the local variable, that you can return o your code as return parameter from the stored procedure.
-
If you are executing your INSERT command in a stored procedure, you can assign ID value of the inserted data to a local variable. Example: declare @returnID -- here goes your insert statement set @return = @@identity With this you have the value of the ID in the local variable, that you can return o your code as return parameter from the stored procedure.
-
If you are executing your INSERT command in a stored procedure, you can assign ID value of the inserted data to a local variable. Example: declare @returnID -- here goes your insert statement set @return = @@identity With this you have the value of the ID in the local variable, that you can return o your code as return parameter from the stored procedure.
Please read the article http://davidhayden.com/blog/dave/archive/2006/01/17/2736.aspx[^]
Regards Aman Bhullar www.arlivesupport.com[^]