Sorry Mac folks, this article is very Windows specific, however, it is worth a read.  How many times it has happened to you that you had to look for a recipe you used or a code snippet you wrote several years ago.  That's easy, you say.
This is my first blog of 2016.  I think 2016 will be an exciting year for the world.

On a different note, the Powerball lottery's jackpot is a record $800 million.  My luck with any kind of gambling has been consistently very bad.  I do not win raffles, football pools etc.
In 2011, I blogged about my experiences with the cheap hosting providers like GoDaddy and 1and1 Hosting.  In the blog I mentioned that 1and1 hosting's SQL panel allows you to run SQL DDL statements using dynamic SQL only.  All creates, drops, grants etc. must be issued using EXEC() statements.
As you know, this series is dedicated to those individuals whose work makes me feel insignificant, and my existence, meaningless.

I love Sudoku.  If I was to put these puzzles into easy, medium, hard, and expert categories, I can deal up to hard level, comfortably.
Back in February 2013, I started a series dedicated to outstanding individuals, whose accomplishments simply dwarfs our own.  In this blog I have chosen this honor to go to Jeremy Kun, a mathematics PhD student.
With this post, I am starting a new segment called, "We are not worthy!"  The segment is essentially to honor ordinary people who create.
Moses said to Yahweh, "O Lord, I am not eloquent, neither before now, nor since you have spoken to your servant; for I am slow of speech, and of a slow tongue."

When it comes to discussing religion, I can relate to Moses.
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.

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
1

View comments

Not too long ago I managed mail servers where each message was stored in a file. Needless to say that there were literally hundreds of thousands of files on the file system.
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.