|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 12:00 PM
Points: 22,
Visits: 33
|
|
Than you for responding to my question.
Respectfully I disagree with your correct solution.
Losing a constraint of not null simply to modify the column length quickly is not a valid option. every. Doing so not only performs the desired result of increasing the column capacity, but it also changes the nullability of a column.
The better option would be to copy the data into a new table using Select ... INTO which would not be transacted. Drop the previous table constraints. Rename the new table, and then re-establish constraints.
If the goal was simply to perform the update quickly, which was not made clear in the problem to be solved, then I can not comprehend how changing the schema is a valid option. I'd revoke rights of any developer who did that on my watch.
Sorry...I'm just bringing real world experience to a theoretical question.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 12:02 PM
Points: 5,243,
Visits: 7,055
|
|
taylor_benjamin (10/2/2010)
Than you for responding to my question. Respectfully I disagree with your correct solution. Losing a constraint of not null simply to modify the column length quickly is not a valid option. every. Doing so not only performs the desired result of increasing the column capacity, but it also changes the nullability of a column. The better option would be to copy the data into a new table using Select ... INTO which would not be transacted. Drop the previous table constraints. Rename the new table, and then re-establish constraints. If the goal was simply to perform the update quickly, which was not made clear in the problem to be solved, then I can not comprehend how changing the schema is a valid option. I'd revoke rights of any developer who did that on my watch. Sorry...I'm just bringing real world experience to a theoretical question.  I agree with your arguments, but I don't understand why this leads you to disagree with the correct answer.
There are two options given. Option 1 does not change the nullability, option 2 does. That alone suffices to conclude that only option 1 can be correct. Option 1 is also faster, which is a nice bonus but nothing more.
The correct answer is: "Option 1 runs faster than Option 2 and is the right choice". Perhaps one might interpret this to mean that it is the right choice because it runs faster. That is not the case. It is the right choice because it preserves the constraints on the table.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 22, 2013 9:32 AM
Points: 547,
Visits: 995
|
|
Just having a look back over older questions (only just noticed the question of the day on newsletters!).
I got this completely wrong but still think I was right at some point. I went with "Option 2 will fail" because I imagined that the loginname column would never be NULL. Therefore trying to switch it from NOT NULL to allowing nulls would cause an error based on the existing 50 million records surely?!? But then I remembered this was on older version of SQL (I have none to test on) and it allows it in 2008? Can anyone confirm that?
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 22, 2013 9:32 AM
Points: 547,
Visits: 995
|
|
| hahahah I love my mind sometimes. I just realised I was thinking backwards (early start). My example WOULD fail if you were allowing NULLS, had a null entered, and then set to NOT NULL. But in this example its the other way round. FOOL!
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 4:12 PM
Points: 382,
Visits: 1,105
|
|
|
|
|