Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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: Wednesday, January 20, 2016 3:10 PM
Points: 481, Visits: 355
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 @ 8:31 AM
Points: 13,975, Visits: 36,285
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
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: Wednesday, January 20, 2016 3:10 PM
Points: 481, Visits: 355
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 @ 8:31 AM
Points: 13,975, Visits: 36,285
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
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: Wednesday, January 20, 2016 3:10 PM
Points: 481, Visits: 355
Thanks

Swarndeep

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

Add to briefcase

Permissions Expand / Collapse