Solved

renumbering records in MS Sql

Posted on 2011-03-25
2
352 Views
Last Modified: 2012-05-11

Is there a way to change the numbers of if a row is deleted using MS sql stored procedure?

For example using the below table, If I delete the row that contains field1 = 15 and field2 =2. I want the field2 rows that contain the values of 3 and 4 to become 2 and 3. I want to add the code to a stored procedure after the row is deleted.

field1, field2, field3
15,      1,      sample                                          
15,      2,      example                                            
15,      3,      model                                            
15,      4,      illustation                                          

                             
0
Comment
Question by:kw66722
2 Comments
 
LVL 5

Accepted Solution

by:
bitref earned 500 total points
Comment Utility
Create a trigger (after delete) to call the following procedure:

Create proc xyz(@DeletedField as int)
Update MyTable
Set field2 = field2 - 1
Where field2 > @DeletedField

Open in new window

0
 
LVL 1

Author Closing Comment

by:kw66722
Comment Utility
Worked like a charm.  Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Creating and Managing Databases with phpMyAdmin in cPanel.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now