How To autoincrement a value of the column [Resolved]

Posted by Anishabathija under Sql Server on 1/16/2013 | Points: 10 | Views : 1080 | Status : [Member] | Replies : 6
Hey ,

I have a column in my table ID. I want to autoincrement it as 1,2,3 ... every time values is entered into the rows. I did read something about using a autoincrement seed , will somebody please throw more light on it.
Thanks!!




Responses

Posted by: Saratvaddilli on: 1/16/2013 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
CREATE 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)
)


Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/16/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
(in design mode)simply go to that column whose value u want to auto increment by 1, its column property block will open below then scroll it down and find Identity specification then open it and double click on IsIdentity property nd set to yes, it will start autoincrementng by one.

njoy
ankit

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shubham on: 1/16/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi!!!! Anishabathija
1st create table like this

CREATE TABLE Student
(
P_Id int PRIMARY KEY IDENTITY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255)
)

To insert a new record into the "Student" table, we will not have to specify a value for the "P_Id" column (a unique value will be added automatically):

INSERT INTO Student (FirstName,LastName)
VALUES ('Lars','Monsen')



Thanks&Regards:-
Shubham Choudhary
Software Engineer
www.facebook.com/shubham.kunar

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anishabathija on: 1/16/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks a ton !!

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/11/2013 [Member] Starter | Points: 25

Up
0
Down


CREATE TABLE EMPLOYEE(EMPID INT INDENTITY, EMPNAME VARCHAR(90), ADDRESS1 VARCHAR(90), ADDRESS2 VARCHAR(90),

CITY VARCHAR(90),STATE VARCHAR(90))


CREATE TABLE EMPLOYEE (EMPID INT IDENTITY (0,1), EMPNAME VARCHAR(90))




sriram

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarthegod on: 5/14/2013 [Member] Starter | Points: 25

Up
0
Down
Create table MyTable
(
ID int Primary key Identity,
Name varchar(23),
Age int
)


Insert into MyTable values('Ashu',23)


Select * from MyTable

Sagar Pandey
Sr. .Net Trainer

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response