Home > Forum > Sql Server > How to insert autoincrement field into SQL Database?

How to insert autoincrement field into SQL Database?

by Thamil   on Jul 28, 2013   Category: Sql Server  |  Views: 3971    |  Points: 5   |  Gold 
  Reply
Hey friends i am student of BCA and currently doing a project on payroll management system and i am having one question

i am having database as back end and field id as auto increment so whenever inseriting data into database with the use form so how to insert data with the form

it seems to give me error to insert data.

Question posted on behalf of Nayan Vyas

Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :How to insert autoincrement field into SQL Database?   
by Thamil
on Jul 28 2013 3:40AM
Points : 10
Gold 
1. Create the table with identity column. basically these identity columns used as a primiray keys in a table and automatically assign the values when every row inserted into table.

create table testtbl(id int identity(1,1),name varchar(100));

2. Execute the below script and select the table

insert into testtbl values('Prabhu');
insert into testtbl values('kumar');

Note: when you pass the parameter from .net side, you need to ignore this identity column.
  Re :How to insert autoincrement field into SQL Database?   
by angappan
on Dec 6 2013 11:44AM
Points : 10
Bronze 
Dear Friend

You Just create table. and select auto increment column go to properties set identity is yes.

when you create table as Query wise do like this

Syntax: Create table tablename(fieldname datatype identity(seed,increment) not null, fieldname2 datatype)
Ex:create table abc(tid bigint identity(1,1) not null, tname varchar(50));

you need to start with identity values as 50, with increment 1,
you just give identity(50,1)

you need to start with identity values as 50, with increment 2,
you just give identity(50,2)

I hope this is useful to you

Thanks and regards
Angappan.S

Recent Post

Latest Posts