Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

About Autonumbering

 
   Database Help (Home) -> Programming RSS
Next:  Access 2007 Table Issue  
Author Message
sam

External


Since: Feb 17, 2010
Posts: 1



(Msg. 1) Posted: Wed Feb 17, 2010 4:41 am
Post subject: About Autonumbering
Archived from groups: microsoft>public>sqlserver>programming (more info?)

i Have an Column Having DataType is Integer.and Column is Auto
numbering.Can I Check any how in database
If Nay Number got deleted then Numbering Should not be rendered e.g

If No Assigned Are 1,2,3,4,5

As if No 4 gets deleted then 5 should go to 4 and New No should be
Assigned as 5

 >> Stay informed about: About Autonumbering 
Back to top
Login to vote
Uri Dimant

External


Since: Aug 24, 2003
Posts: 1744



(Msg. 2) Posted: Wed Feb 17, 2010 9:25 am
Post subject: Re: About Autonumbering [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Take a look into ROW_NUMBER function if you are using SQL Server 2005 and
onwards




"sam" wrote in message

>i Have an Column Having DataType is Integer.and Column is Auto
> numbering.Can I Check any how in database
> If Nay Number got deleted then Numbering Should not be rendered e.g
>
> If No Assigned Are 1,2,3,4,5
>
> As if No 4 gets deleted then 5 should go to 4 and New No should be
> Assigned as 5

 >> Stay informed about: About Autonumbering 
Back to top
Login to vote
Plamen Ratchev

External


Since: Aug 20, 2008
Posts: 672



(Msg. 3) Posted: Wed Feb 17, 2010 9:54 am
Post subject: Re: About Autonumbering [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

If you want to avoid gaps then you have to use custom sequence generation. See one example here:
http://www.sqlmag.com/Article/ArticleID/101339/sql_server_101339.html

--
Plamen Ratchev
http://www.SQLStudio.com
 >> Stay informed about: About Autonumbering 
Back to top
Login to vote
Gert-Jan Strik

External


Since: Feb 19, 2010
Posts: 6



(Msg. 4) Posted: Fri Feb 19, 2010 3:25 pm
Post subject: Re: About Autonumbering [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

sam wrote:
>
> i Have an Column Having DataType is Integer.and Column is Auto
> numbering.Can I Check any how in database
> If Nay Number got deleted then Numbering Should not be rendered e.g
>
> If No Assigned Are 1,2,3,4,5
>
> As if No 4 gets deleted then 5 should go to 4 and New No should be
> Assigned as 5

You should ask yourself if you really want to renumber any rows when you
delete one of the rows. Would that renumbering really serve any purpose?
If you want sequential numbering, then it might be better to add this
only in your select queries (as Uri suggested).

And renumbering many rows will have serious impact on performance.
Suppose your table has 1,000,000 rows, and you delete row with ID 2.
Then 999,998 rows have to be renumbered. And if the ID is part of the
clustered index, then not only will all rows be updated, but all indexes
will have to updated as well. That makes deleting a row a very
cumbersome process.

--
Gert-Jan
 >> Stay informed about: About Autonumbering 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
need help with query - I want to sum the records in a table (u) which have 'P.M.' in a field value and test against a fixed limit something to the effect of : case when SUM(substring(u.sTime,1,4)='P.M.') <= 64 Then .... except it should work ...

Next?? - I have a field stored as NTEXT(16). I need to replace some of the content in this field. I know the replace function doesnt work. I see there is UPDATETEXT - is this the ONLY way to do it ?? 'cos it looks quite complicated? thanks, Justin

How can I get the resultset from a stored procedure - I have a stored procedure which will output a table. How can I use a sql statement to get the result of the sp? Thanks a lot

Audit V2 - I am looking to write a SQL script that will show me for each table, in all the databases on a server, which users / groups have access. In addition, I want to break the access into whether it is SELECT, UPDATE, INSERT or DELETE permissions. Is this..

Detecting an existence of local temporary table - Hi, I create a temporary table. for example: <font color=purple> ; create table #t1 (ID_T1 integer)</font> Next I would like to detect If the table already exists: exec sp_table #t1 if @@ROWCOUNT > 0 <font color=purple>&...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]