Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> Database >> Auto increment id by using stored procedure
Auto increment id by using stored procedure

In this blog I am going to demonstrate that how to increment id of table automatically by using stored procedure.
Views: 7725     Comments: 2
by Awadhendra Tiwari on 3/15/2011

In this blog I am going to explain that how to create a procedure which automatically increment id of table. For implementing this task I had created a table which has two columns such as id and name. Value in id column
is automatically inserted by procedure and value in name column is passed by variable in procedure.

Creating a table in SQLSERVER

create table AutoIncrementTable

(

     id bigint,

     name varchar(50)

)

After creating table now I am going to create a paramentrized stored procedure which insert value in table and
accept name as parameter. This procedure insert id in table automatically and increment id by 1.

Creating parametrized stored procedure

alter proc p_auto_increment_table_proc

@name varchar(50)

as

declare @Id bigint

select @Id=count(Id)+1 from AutoIncrementTable

begin

     insert into AutoIncrementTable values(@Id,@name)

end

After creating stored procedure now execute it and see the result.

Executing stored procedure

p_auto_increment_table_proc 'Alok'

This will insert record in table and each time id is automatically incremented.




Auto increment id by using stored procedure
by Amit Singh on 3/25/2011
This is the helpful article
Thanx
Report Abuse

Good Stuff
by mohan kumar on 3/13/2012
Good Stuff..
Report Abuse
Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 7213
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.