Solved

Is there a way to manually change/update  an ID number in SQL Server Management Studio

Posted on 2010-11-18
8
249 Views
Last Modified: 2012-05-10
The ID number are auto-incremental and some rows were deleted so there are numbers in between where there are a couple of instances were I would like to change one or two of those ID numbers for continuity but is grayed out. Is there a way to do this with the GUI interface?

For example I have rows

1
4
5
6
7

I would like to change the 4 to a 2 and the 5 to a 3.
ID is the primary key and is set to "identity".

Thank you in advance.
0
Comment
Question by:colonelblue
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 375 total points
ID: 34166554
Hi,

You can do that by

DBCC CHECKIDENT('YourTableName', RESEED, 1)
0
 
LVL 28

Assisted Solution

by:sammySeltzer
sammySeltzer earned 125 total points
ID: 34166558
use identity reseed

DBCC CHECKIDENT (yourtable, reseed, startnumber)


0
 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 375 total points
ID: 34166579
Hi,

As you said its PK so if other table relates to this table then you need to check integrity of FK.

either you need to update id of FK table.

or need to change cascade relations.
0
 

Author Comment

by:colonelblue
ID: 34169298
Thank you both. If you don't mind me asking since I am more reliant on using the GUI ( For example using the diagrams, dropdown boxes, clicks ) because I am a newb and wouldn't even know where to run that code for a single row, is there a way to do it using the interface?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 375 total points
ID: 34169872
Hi.

Just paste one of the code in query window.

Give table name where i write ur tablename.

Select database from database list which u want to use.

If you wanted to do via GUI then open ur table in design mode,first set auto identity to No for id column.

2nd save the table

3rd again set yes to auto identity column.

I knw u r new to sql but try 2 do,if u stuck,we are here to help u.

I suggest go with 1st option.
0
 

Author Closing Comment

by:colonelblue
ID: 34170482
Thank you especially Brichsoft.
You guys are awesome.
0
 
LVL 22

Expert Comment

by:dportas
ID: 34171712
Only use the GUI in this way if you have a backup or don't mind losing the data. Also make sure there is no-one else using the database. Using the GUI to modify tables like this can sometimes render the whole database ususable.

I strongly recommend you learn to use T-SQL so that you can write and execute SQL statements properly - that way you will have much more control over what you are doing.

IDENTITY columns have the irritating "feature" that they don't permit updates on the column. The easiest way to get around this may be to delete the rows and reinsert them.

The new SQL Server 2011 supports sequences, which makes it easier to create a surrogate key that you can update.
0
 
LVL 22

Expert Comment

by:dportas
ID: 34171719
Correction: "ususable" = "unusable"
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

21 Experts available now in Live!

Get 1:1 Help Now