Sql server will not let you dropa table if it has default contraints (like default values for columns.)
This script will let you find them.
1. Determine the constraint name.

if object_id('[dbo].[GetDefaultConstraintName]') is not null
    drop function [dbo].[GetDefaultConstraintName]
go

create function [dbo].[GetDefaultConstraintName] (
    @TableName varchar(max),
    @ColumnName varchar(max))
returns varchar(max)
as
begin

    -- Returns the name of the default constraint for a column

    declare @Command varchar(max)
    select 
        @Command = d.name
    from 
        ((
        sys.tables t join
        sys.default_constraints d
            on 
                d.parent_object_id = t.object_id) join
        sys.columns c
            on 
                c.object_id = t.object_id and 
                c.column_id = d.parent_column_id)
    where 
        t.name = @TableName and 
        c.name = @ColumnName
    return @Command
end
go

2. Generate dynamic sql to drop the constraint. Assume that the table name is MyTable and the column name is MyColumn.
execute ('alter table MyTable drop constraint '+
           [dbo].[GetDefaultConstraintName]('MyTable','MyColumn'))

3. Re-create the constraint with the desired default value. Assume that the new default value should be 33.
alter table MyTable add constraint [DF_MyTable_MyColumn] default (33) for MyColumn
Rigged democratic primary in New Jersey
Crystal Report Nuances using Microsoft Access Database
Getting digitally organized my way
Getting digitally organized my way
Play hard Powerball
Play hard Powerball
1
Setup a remote Git repository with bargain Unix hosting provider
16
1AND1 Formatter Utility
1AND1 Formatter Utility
We are not worthy series - Building Sudoku Puzzles
We are not worthy series - Building Sudoku Puzzles
We are not worthy series - A Math Genius
We are not worthy series - A Math Genius
Home made pastrami
1
We are not worthy - The new segment
We are not worthy - The new segment
1
Certified Hindu guide!
Certified Hindu guide!
SQL Server script to find table dependencies
1
How to bring U.S.Postal Service to profitability
2
Basement Thingamajig
4
Web user control - Demystified
3
Get default constraint name for Table/Column (SQL Server 2005/2008)
Get default constraint name for Table/Column (SQL Server 2005/2008)
1
Life in the BBQ lane
4
Best mass file delete utility for Windows platform
Best mass file delete utility for Windows platform
6
About Me
About Me
My Photo
Piscataway, New Jersey, United States
I am an electrical engineer by education and a software developer by profession. I like building electro-mechanical models. I also like grilling and barbecuing with passion. To burn my beer cals, I swim and run. I usually post my DIY projects on: http://www.instructables.com/member/kabira/
Blog Archive
Loading
Dynamic Views theme. Powered by Blogger.