C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







generate id in sql server 2005


Posted Date: 05 Jul 2008      Total Responses: 5

Posted By: samatha g       Member Level: Gold     Points: 1


i want to generate id automatically in sqlserver 2005.now iam able to generate but if i delete a record from middle the id should refresh automatically.how is it possible?plssssssss help me?



Responses

Author: Sri Harsha    05 Jul 2008Member Level: SilverRating:     Points: 3
HI,

Write a "After" trigger with the update statement on the ID Column, So whenever the Deletion from the table happens the trigger fires and update the respective column.


Author: Satyanarayan SushilKumar Bajoria    05 Jul 2008Member Level: DiamondRating:     Points: 4
Hi,

You can use a After trigger in this scenario because in case of After trigger the data is first inserted into table and then copy into the magic table,so in magic table.

So whenever the Deletion from the table happens the trigger fires and update the respective column.

Thanks and Regards
S.S.Bajoria



Author: Mohd. Vaseem    05 Jul 2008Member Level: SilverRating:     Points: 1
Hi,

Updating Ids from After trigger will cause the problem of id references to others table.

Suppose You have following table data

Id Name Sal
1 AA 5000
2 BB 6000
3 DD 12000

Now you deleted 2nd record then after trigger will update the table like

Id Name Sal
1 AA 5000
2 DD 12000 (Previous Id 3)

That may create problem if somewhere Id=3 have any reference.

Instead of this you can create a view having a separate row Number column, which will allways display you sequential numbers even u delete some records from middle of tables.

Thanks
Vaseem



Author: Vijaya    05 Jul 2008Member Level: DiamondRating:     Points: 4
Hi,
When you say refresh means you want to adjust the ID automatically??? Why do you want to do it? What will u get by doing this? Its easy to give any solution, but its very important to understand the requirement and provide right direction.
Thanks -- Vj
http://dotnetvj.blogspot.com



Author: Gaurav Agrawal    06 Jul 2008Member Level: DiamondRating:     Points: 3
Register urself on this site for earning money by using this link

http://www.rupeemail.in/rupeemail/invite.do?in=MTAxNTM0JSMlS0hqblZtUFI0c3BmTmw2azNNVDhyb1dCaA==

GA



Post Reply
You must Sign In to post a response.
Next : stored procedure
Previous : oracle update query
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

Help Desk

Contact Us    Privacy Policy    Terms Of Use