Solved

renumbering records in MS Sql

Posted on 2011-03-25
2
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
bitref earned 500 total points
ID: 35219262
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
ID: 35219755
Worked like a charm.  Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tempdb log keep growing 7 54
mysql vs miscrosoft sql server 6 52
MDT Create a bootable media for BIOS 2 20
Code not executing correctly. 3 40
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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