Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Fixing CREATE TABLE


Fixing CREATE TABLE

Author
Message
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: Administrators
Points: 35998 Visits: 18728
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
My Blog: www.voiceofthedba.com
doug 2339
doug 2339
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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.
Gary Varga
Gary Varga
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8251 Visits: 6123
That's a great illustration of one of the reasons SELECT * FROM is such a bad practice!!!

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search