RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums
Views: 78312 | Replies: 10
Reply
Join Date: May 2005
Location: Cleveland, OH
Posts: 3
Reputation: Madmax is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Madmax Madmax is offline Offline
Newbie Poster

Autonumber in a SQL Server table

  #1  
May 17th, 2005
I know this is probably a stupid post but I cannot think of how to accomplish this. How do you do the equivilent to an autonumber in a SQL Server table? Please let me know my project is very close to deadline
Thanks in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Autonumber in a SQL Server table

  #2  
May 17th, 2005
Ok, just to clarify? Replicate autonumber in SQL how? You mean within an SQL function/store procedure or in another coding lanuage (if so which one)?

IDENTITY(x,y) is how you use autonumber in SQL ( x = starting point, and y = increment by)
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Join Date: May 2005
Location: Cleveland, OH
Posts: 3
Reputation: Madmax is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Madmax Madmax is offline Offline
Newbie Poster

Re: Autonumber in a SQL Server table

  #3  
May 17th, 2005
Originally Posted by Paladine
Ok, just to clarify? Replicate autonumber in SQL how? You mean within an SQL function/store procedure or in another coding lanuage (if so which one)?

IDENTITY(x,y) is how you use autonumber in SQL ( x = starting point, and y = increment by)


I just needed to know syntax on how to get an autonumber like column for MS SQL Server. So in your example if my field was "bill" lets say when I set it up in the design table area of SQL server I would enter "bill" in the column name field and then enter numeric in the data type field. Then set up the incrementation in a stored proc? Am I in the ball park here?
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Autonumber in a SQL Server table

  #4  
May 18th, 2005
Well kind of.

Ok here is the syntax on creating a table in SQL and having an autonumber column
CREATE TABLE NorthWindUsers 
         (UserID INT IDENTITY(1,1) NOT NULL,
          UserName VARCHAR(50) NOT NULL,
          Password VARCHAR(50) NOT NULL)

The userID will start a 1, and increment each time you add a new user to the table; automatically


Hope this helps
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Join Date: Jun 2005
Posts: 12
Reputation: relawson is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
relawson relawson is offline Offline
Newbie Poster

Re: Autonumber in a SQL Server table

  #5  
Jun 11th, 2005
Originally Posted by Paladine
Well kind of.

Ok here is the syntax on creating a table in SQL and having an autonumber column
CREATE TABLE NorthWindUsers 
         (UserID INT IDENTITY(1,1) NOT NULL,
          UserName VARCHAR(50) NOT NULL,
          Password VARCHAR(50) NOT NULL)

The userID will start a 1, and increment each time you add a new user to the table; automatically


Hope this helps


You know, this feature isn't in Oracle as I recently discovered. Is it considered bad to use autoincrementing numbers? Certainly makes it easy to maintain a primary key with little effort. I am just trying to understand in what situation you wouldn't want to use that feature. Obviously Oracle doesn't seem to want you to use it at all.
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 345
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Autonumber in a SQL Server table

  #6  
Jun 12th, 2005
Originally Posted by relawson
You know, this feature isn't in Oracle as I recently discovered. Is it considered bad to use autoincrementing numbers? Certainly makes it easy to maintain a primary key with little effort. I am just trying to understand in what situation you wouldn't want to use that feature. Obviously Oracle doesn't seem to want you to use it at all.

I don't know that Oracle thinks it is a bad thing, they just choose to solve the problem a different way--with "sequences". In Oracle, as you may know, a sequence is it's own thing outside of any table. Personally, I wish the databases I work with had both an autonumber/identity and a feature like a sequence. They are both very handy. A sequence can be useful if you need a way to have an id unique across multiple tables or multiple databases.

It's easy enough to code your own sequence-like feature using a one column/one row table and a function, but I assume Oracle's sequence feature is highly optimized to do what it does.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Sep 2006
Posts: 3
Reputation: Zandyke is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Zandyke Zandyke is offline Offline
Newbie Poster

Re: Autonumber in a SQL Server table

  #7  
Sep 14th, 2006
Easy actually, just add a column call it whatever and set data type to be
int, and below set the IDENTITY to YES. ur good to go.....
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:51 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC