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.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Article: Default Constraint Names
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 01/23/2001 :  10:18:51  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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 Posts

Posted - 01/30/2004 :  08:30:05  Show Profile  Reply with Quote
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 Posts

Posted - 05/09/2005 :  14:24:23  Show Profile  Reply with Quote

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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000