alter table and add defalut

  • I have a column that I need to change the size in multiple production servers.

    I have also a default on this column and it is not null.

    I use a SP (custom written) to drop the default and then change the column size from int to big int, but then I cannot recreate the default for this Not Null column with the alter table... alter column statement.

    Is there a way to do that within the Alter table - alter column statement? Some work around?

    Thanks a lot, mj

  • you could simply add the constraint to the table: you might need to update the table to the new value prior to adding the constraint

    update mytable set myNewColumn=50 where MyNewColumn is null;

    ALTER TABLE MyTable

    ADD CONSTRAINT DF_MyCol_Default

    DEFAULT 50 FOR MyNewColumn ;

    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!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply