|
Posted by Erland Sommarskog on 07/24/06 21:44
Erland Sommarskog (esquel@sommarskog.se) writes:
> Giacomo (no_spam@grazie.it) writes:
>> P.S.
>> We're using SQL Sever 2000 (version 8.00.194)
>
> Before you do anything else, install SP4. What you have is the RTM version
> which is five years old, and there are many bugs that have been fixed.
> Not the least the hold that made the Slammer worm possible.
>
> No, it will not address your problem at hand, and being at work now I
> don't have the time to post the exact code. You will need to read the
> system tables to get the name of the default and then use dynamic SQL to
> run ALTER TABLE DROP CONSTRAINT. Best practice is to always name your
> defaults, so that you don't run into this problem.
So this is how you do it:
DECLARE @default sysname
SELECT @default = object_name(cdefault)
FROM syscolumns
WHERE id = object_id('yourtable')
AND name = 'yourcolumn'
EXEC ('ALTER TABLE yourtable DROP CONSTRAINT ' + @default)
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|