Home » SQL ServerRSS

Autonumber Primary Key

Good afternoon and thanks in advance for your help. 

How do I assign the autonumber property to my primary key? 

 

8 Answers Found

 

Answer 1

In what kind of database?

SQL Server, Access, Oracle, etc?

I could guess you have an Access database, as you used the term "autonumber", but answers will vary by database type, and in Access, version.

 

 

Answer 2

In SQL Server set the Identity property for the int (or bigint) field.

 


Premature optimization is the root of all evil in programming. (c) by Donald Knuth

Naomi Nosonovsky, Sr. Programmer-Analyst

My blog
 

Answer 3

Since you asked this question in SQL Server forum, I am assuming your question is pertaining to SQL Server

to add into Naomi's reply

See IDENTITY prorprety in SQL Server books online

http://msdn.microsoft.com/en-us/library/ms186775.aspx

e.g.

CREATETABLE Person
(
 id_num intIDENTITY(1,1) PRIMARYKEY,
 fname varchar (20),
 minit char(1),
 lname varchar(30)
)


 

Answer 4

SQL Server 2008 R2 - My experience is with Access... 
 

Answer 5

Thanks for your feedback. 

 

Identity Specification = YEs

(Is Identity) = Yes

Identity Increment = 1

Identity Seed = 1

 

Does the above look correct? 

 

Answer 6

Yes, that is correct as you are doing in SQL Server management studio table designer.

 

 

Answer 7

In that case, Naom has answered your question.
 

Answer 8

Also please check out DBCC CHECKIDENT  command

BOL says

A. Reset the current identity value, if needed

This example resets the current identity value, if needed, of the jobs table.

USE pubs
GO
DBCC CHECKIDENT (jobs)
GO
B. Report the current identity value

This example reports the current identity value in the jobs table, and does not correct the identity value, if incorrect.

USE pubs
GO
DBCC CHECKIDENT (jobs, NORESEED)
GO
C. Force the current identity value to 30

This example forces the current identity value in the jobs table to a value of 30.

USE pubs
GO
DBCC CHECKIDENT (jobs, RESEED, 30)
GO
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter