Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i have created a table for UserId, UserName. my doubt is how can i increment the Userid. that is no need of entering always the Userid while inserting into the Database table.
 

it is resolved thanks for all ur answers
Posted 18-Dec-12 22:50pm
Edited 11-Feb-14 1:14am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use IDENTITY (Property)[^] for userID column. This will auto increment the userID automatically when an user is inserted into the user table.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

While making the SQL Table, you can make the required column Autoincrement(Identity=true), the column must be of int datatype. Then when ever the data is inserted into the table. The column automatically increment the set value.
 
try to create this table.
 
CREATE TABLE [dbo].[testtable](
	[userid] [int] IDENTITY(1,1) NOT NULL,
	[username] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
 
GO
SET ANSI_PADDING OFF
 
Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can set an auto-increment option while designing the table.
This will automatically increment the value everytime a row is inserted.
 
Try
http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/[^]
http://www.sitepoint.com/forums/showthread.php?41676-Auto-Increment-primary-key-in-MS-SQL-server[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

this is demo but but it is useful for Auto ID
 

create table #tblTest(UserId  int,UserName varchar(50))
 
insert into #tblTest(UserId,UserName)
select isnull(max(UserId),0)+1,'Your Use Name' from #tblTest
 
select * from  #tblTest
drop table #tblTest
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 5 May 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100