Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mcupryk
Yak Posting Veteran
91 Posts |
Posted - 2015-03-06 : 15:21:54
|
I have the following:CREATE TABLE [Lookup].[Countries]( [Id] [int] IDENTITY(1,1) NOT NULL, [Code] [nvarchar](2) NOT NULL, [Name] [nvarchar](70) NOT NULL) ON [PRIMARY]GOI need to fix the below so the identity starts at 1 instead of 248-----Id Code Name248 AD Andorra249 AE United Arab Emirates250 AF Afghanistan251 AG Antigua And Barbuda252 AI Anguilla253 AL Albania254 AM Armenia255 AO Angola256 AQ Antarctica257 AR Argentina258 AS American Samoa259 AT Austria260 AU Australia261 AW Aruba262 AX Aland IslandsAny help would be awesome. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2015-03-07 : 08:31:21
|
If the data is already in the table, for small to moderate sized tables, the easiest way is to repopulate the table.-- save the data. After this step, make sure that you have the data in the new table.select * into dbo.ATempTable from [Lookup].[Countries];GO-- truncate table. This also resets the identity seed.truncate table [Lookup].[Countries];GO-- re-insert the datainsert into [Lookup].[Countries] select Code, Name from dbo.ATempTable;GO-- verify that you have the right data in the original table, and then drop it.drop table dbo.ATempTable; |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2015-03-07 : 13:12:30
|
First and most important question of them all is "Why does it matter?".It's a surrogate key and as such, no logic should be placed onto it. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|