Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Gap sequence of column_id Expand / Collapse
Author
Message
Posted Tuesday, December 15, 2009 10:11 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 8:42 AM
Points: 481, Visits: 318
select * from sys.columns where object_id = object_id('tablename')

This query returns all the columns in the table, however, the column id in between is breaking the sequence. For example after column_id 26, 28 appears but 27 is missing. However the column names are correct and in correct order.

This is causing issues when performing change manager operation.

Does anyone has any idea, how this can be fixed?

Thanks


Swarndeep

http://talksql.blogspot.com
Post #834627
Posted Tuesday, December 15, 2009 10:31 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:23 AM
Points: 12,915, Visits: 32,074
if you add a drop columns from a table, the column_id is dropped with it; then when you add additional columns, the next column_id is used.

so if you drop column 4 in a 7 column table, and add another, column_id4 is lost...columns 5 thru 7 do not shift over.

perfectly normal to see gaps in the column_id; that's by design.

if you have another process that is counting from 0 to max(column_id), you'd want to change it to use something like a For Each Column in ColumnCollection.
the only other alternative is to rebuild the tables; i'd recommend using the SSMS GUI, as it handles all the heavy lifting behind the scene...identifying all constraints/foreign keys/defaults/etc, dropping em building new table,dropping old table,renaming new, re-adding all the constraints back.


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #834636
Posted Tuesday, December 15, 2009 10:38 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 8:42 AM
Points: 481, Visits: 318
Thanks for reply with explanation. I will contact technical support of change manager (DBGhost), which works in this way and there is nothing wrong with tables.

Swarndeep

http://talksql.blogspot.com
Post #834639
Posted Tuesday, December 15, 2009 10:40 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:23 AM
Points: 12,915, Visits: 32,074
here's a quickie SQL to find tables with "gaps" in the column_id sequence:
select distinct object_name(object_id) As TableWithGaps 
from (
select * ,
row_number() OVER(partition by object_id order by column_id) As RW
from sys.columns ) X
where RW <> column_id



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #834640
Posted Tuesday, December 15, 2009 10:44 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 8:42 AM
Points: 481, Visits: 318
Thanks

Swarndeep

http://talksql.blogspot.com
Post #834641
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse