I have a table abc in mssql which has column xyz which has its default has been set to not null, so the insert query fails when it has null value, I need help to change the default so that it accepts null values, table has only one constraint and its not on the column that I want to modify .
            Asked
            
        
        
            Active
            
        
            Viewed 47 times
        
    0
            
            
        - 
                    `not null` is not a constraint. it's part of the table definition. `alter` the table. – Marc B Oct 06 '15 at 15:54
- 
                    I mentioned about the constraint because that's the post I saw on here,but anyways,,can you help me with the query ? – Dr.Grey Oct 06 '15 at 16:01
- 
                    this is what I tried : ALTER TABLE list ALTER COLUMN MED DEFAULT(NULL); – Dr.Grey Oct 06 '15 at 16:03
2 Answers
0
            
            
        ALTER TABLE xyz
ALTER COLUMN xyz NVARCHAR(10) NULL
Alter should work fine here, obviously change NVARCHAR(10) to whatever type you need
 
    
    
        Ross
        
- 112
- 1
- 17
0
            
            
        According to (How to set a default value for an existing column)
You have 2 options: 1. Setting a constraint: ALTER TABLE Employee ADD CONSTRAINT DF_SomeName DEFAULT N'SANDNES' FOR CityBorn;
- Add Default: ALTER TABLE Employee ADD DEFAULT 'SANDNES' FOR CityBorn
 
    
    
        Community
        
- 1
- 1
 
     
    