By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

To Generate serial number automatically

P: 71
Hi all,
I need to insert a column in a table as sno but it should generated numbers from 1,2,3,.....It is similar to ms excel's auto number.Tel me a way to do it in SQL Express.

Cheers
Jeen
Oct 10 '07 #1
Share this Question
Share on Google+
3 Replies


iburyak
Expert 100+
P: 1,017
Try this:


Expand|Select|Wrap|Line Numbers
  1. Alter your_table_name add ID int identity(1,1)
When you issue insert statement omit mentioning this column and number will be generated automatically.
Oct 10 '07 #2

ck9663
Expert 2.5K+
P: 2,878
one catch...

identity columns ensures uniqueness but not "sequential-lity" (if there's even a word)...
Oct 10 '07 #3

P: 71
Thanks to all. I tried ur solution and its working....
Oct 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.