Solved

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

Posted on 2010-11-18
8
268 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
[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
  • 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 29

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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
 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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