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 «««123

Fixing CREATE TABLE Expand / Collapse
Posted Thursday, February 27, 2014 10:00 AM



Group: Administrators
Last Login: Today @ 9:24 AM
Points: 34,366, Visits: 18,587
GBimberg (2/27/2014)
If you could alter tables the way you suggest, it would appear that you could also change the column order and type.

Accidently changing the column order and type would cause nightmares.

If you couldn't change the column order and type, altering tables this way would just be a huge pain in the a$$.

I'm not sure this is a good reason. A warning could be used here, and a good IDE would detect this. You might want this, but most likely not. However, are we not saying that programmers should be protected from making mistakes? I would argue that part of what we want to do is get programmers to be careful and confident of what they submit.

In terms of ordering, does it matter? The physical implementation shouldn't matter. The order of columns in the CREATE TABLE should only be a semantic display issue for results, not impacting the physical storage. Surely we could handle meta data changes in system tables if someone reordered columns.

Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1545987
Posted Tuesday, March 4, 2014 8:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 4, 2014 8:35 AM
Points: 2, Visits: 10
I have used alter table / alter column many times and not thought about it. When I was consulting as a DBA for a state child services agency using DB2 on mainframe, I learned a valuable lesson why you have to think carefully about this when working large data sets.

Extending a column in the middle of a database can force a reordering of all of the extents in the database. In this case, the data size involved would be on the order of hundreds of millions of rows and terabytes of data. (For the record, the DBA team told the developer who wanted to make this change so that he could store additional notes to go and figure out a better way to do it.)

Adding an extra column at the end of the table, on the other hand, does not require any re-ordering of data. Many times, I think that individuals are taught the latter method without explaining why. If you're creating the table and fixing it right away, go for the alter. If you have 10M rows, you might think about it differently.
Post #1547383
Posted Tuesday, March 4, 2014 10:54 AM



Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 7,917, Visits: 5,963
That's a great illustration of one of the reasons SELECT * FROM is such a bad practice!!!


-- Stop your grinnin' and drop your linen...they're everywhere!!!
Post #1547452
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse