Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Article Discussion
 Article: Default Constraint Names

Author  Topic 

Ask SQLTeam Question

0 Posts

Posted - 2001-01-23 : 10:18:51
A DBA I know named Lance sent me a view and a write-up on it and asked if I'd like to publish it. He posts in the forum under JohnDeere. Lance was fighting with server named default constraints and was using the view to help manage and rename the constraints.

Article Link.

Starting Member

1 Post

Posted - 2004-01-30 : 08:30:05
There's a script for dropping default constraints of unknown names at the bottom of [url=]this[/url] page.
Go to Top of Page

Starting Member

1 Post

Posted - 2005-05-09 : 14:24:23

My problem was that I need to alter some columns, but the alter statement throw an error: Cannot alter column ... its being replicated.
I was wondering about that error message bacause there are no replications on my database. I run sp_help on that table then realized that my column has a default value wich creates a default constraint.
Because the alter runs in an install kit, i had to have a script what drops the default constraint from that column.

I think the MSDN link is very useful, but the script doesn't work, so I made one based on that.
Here it is:
-- this script drops the default constraint from the given column in the given table
DECLARE @tablename VARCHAR(100),@columnname VARCHAR(100),@tab VARCHAR(100)
SET @tablename='TABLE'
SET @columnname='COLUMN'

declare @defname varchar(100)
declare @cmd varchar(100)

select @defname = name
FROM sysobjects so JOIN sysconstraints sc
ON = sc.constid
WHERE object_name(so.parent_obj) = @tablename
AND so.xtype = 'D'
AND sc.colid =
(SELECT colid FROM syscolumns
WHERE id = object_id(@tablename) AND
name = @columnname)

select @cmd='alter table '+@tablename+ ' drop constraint '+@defname
if @cmd is null print 'No default constraint to drop'
exec (@cmd)

Jason, thanks for your link, it helped me to write my own code.

Go on SQL Team!
Go to Top of Page

- Advertisement -