SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

AskSQLTeam
Ask SQLTeam Question

USA
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.

JamieKitson
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=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlpro2k/html/sql00a11.asp]this[/url] page.
Go to Top of Page

Tsabi
Starting Member

Hungary
1 Posts

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

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 so.id = 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!
Regards,
Tsabi
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000