February 22, 2011 at 11:22 am
I have table of Student_Details where StudentID is int type and set as Primary Key. I want when any new record innserted in table the value of StudentID will increase by 1 automatically. How can i do it? I try but not getting a solution of it.
February 22, 2011 at 11:32 am
Make it an "identity" column.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
February 22, 2011 at 11:56 am
Hello,
I have already set the identity as Yes and increse the value by 1. So when I enter a new record there it shows null as in StudentID not showing 2 as per for 2nd record. I want the value of this field (StudentID) will increse from last record (that is 1 ) to 2 in next record. Waiting your reply...
February 22, 2011 at 1:11 pm
Depending on the application you are using to access the data, it won't generate the ID value until you actually submit the data to the database.
Generally, that means clicking on a "Save" or "Submit" or "Ok" button, or hitting the "Enter" key on your keyboard once you type in the data.
Once you've done that, it will assign the ID. It can't assign it till the data is submitted to the database.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
February 22, 2011 at 1:52 pm
with MySelect as
(
SELECT Name,
RANK() over(order by UserId) as newUseId
from TableUsers
)
-- Inserts
SELECT newUseId,
'INSERT TableUsers( ... ) VALUES ( '''+ UserId + ''',' + '...)' as SQL1
FROM MySelect
February 23, 2011 at 1:58 am
hello you are right,
when insert a new recordand press tab to new rows then StudentID is automatically changed from null to 2 for 2nd record.
Many many thanks for giving a such valuable time for my post.
February 23, 2011 at 6:28 am
You're welcome.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply