Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 12th, 2008, 04:05 PM
danja danja is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 140 danja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 36 m 56 sec
Reputation Power: 4
Exclamation SQL Server 2000 - Force primary ID

How to force the primary key for a table to begin at a set Primary Id and not standard count (1,2,3,4,5..10,11,12) etc.

Pretty much how to force it being on number I would like to begin.

Reply With Quote
  #2  
Old May 12th, 2008, 04:21 PM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,867 mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 4 Weeks 15 h 20 m 54 sec
Reputation Power: 1762
have a look in BOL for "DBCC CHECKIDENT" ...
__________________
Come JOIN the party!!!

Quote of the Month:
Retirement: Because you've given so much of yourself to the company that you don't have anything left we can use.

Questions to Ponder:
What do you do when you see an endangered animal eating an endangered plant?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright© 2008 sbenj69

Reply With Quote
  #3  
Old May 12th, 2008, 04:25 PM
dykebert dykebert is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 268 dykebert User rank is Second Lieutenant (5000 - 10000 Reputation Level)dykebert User rank is Second Lieutenant (5000 - 10000 Reputation Level)dykebert User rank is Second Lieutenant (5000 - 10000 Reputation Level)dykebert User rank is Second Lieutenant (5000 - 10000 Reputation Level)dykebert User rank is Second Lieutenant (5000 - 10000 Reputation Level)dykebert User rank is Second Lieutenant (5000 - 10000 Reputation Level)dykebert User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 8 h 41 m 29 sec
Reputation Power: 99
I've done this 2 different ways.

1. Add n-1 blank records so that your real data starts at record n. Then delete the blank recods.

2. There is a command to turn off the primary key autonumber and allow you to insert the primary key. Insert your first record with the primary key you want, then turn the primary key back on. (Sorry I forget the command I just remember that I've done it.)

Reply With Quote
  #4  
Old July 6th, 2008, 04:28 PM
homerorivera homerorivera is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: Monterrey, Mexico
Posts: 18 homerorivera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 27 m 53 sec
Reputation Power: 0
From The Point Where You Create The Table

This is not a PRIMARY KEY problem, but an IDENTITY issue.

IDENTITY sets the counter for a column.
When creating a column for a table that you want a counter on, you need to use an IDENTITY property for the column as follows:



CREATE TABLE dbo.TestTable
(
TestID int IDENTITY(1,1)
, TestText varchar(100) NOT NULL
, .....
)


the parameters in the IDENTITY are Identity Seed and Increment.

If you use
IDENTITY(1000, 3)

your ID will start at 1000 and the next column will be 3 units bigger as in:
1000
,1003
,1006
,1009
, etc...





I could be, anyway, switching the places, maybe the first place is for the incrementals and the second one for the seed.
If it doesn't work right, please try it this other way.

GOOD LUCK






Quote:
Originally Posted by dykebert
I've done this 2 different ways.

1. Add n-1 blank records so that your real data starts at record n. Then delete the blank recods.

2. There is a command to turn off the primary key autonumber and allow you to insert the primary key. Insert your first record with the primary key you want, then turn the primary key back on. (Sorry I forget the command I just remember that I've done it.)

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > SQL Server 2000 - Force primary ID


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT