[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

create an autonumber in sql

Posted on 2011-10-03
5
Medium Priority
?
314 Views
Last Modified: 2012-05-12
I have a table named MonthlyReport.  How do I create a field that is called ID and has autonumber built into it?
0
Comment
Question by:al4629740
5 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 300 total points
ID: 36907691
Mark the field as an "identity" field and set the seed and increment values.
0
 

Author Comment

by:al4629740
ID: 36907704
example please,,,
0
 
LVL 15

Assisted Solution

by:Minh Võ Công
Minh Võ Công earned 600 total points
ID: 36907722
REATE TABLE Persons
(
P_Id int NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
PRIMARY KEY (P_Id)
)
http://www.w3schools.com/sql/sql_autoincrement.asp
0
 
LVL 15

Assisted Solution

by:Minh Võ Công
Minh Võ Công earned 600 total points
ID: 36907727
0
 
LVL 9

Accepted Solution

by:
mimran18 earned 1100 total points
ID: 36907899
Hi
    Here is the example :

Alter table [MonthlyReport] Add [ID] int identity (1,1)
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

873 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