Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Drop Every Default Constraint - SQL Server

RSS
Modified on Sat, Oct 25, 2008, 10:17 PM by Administrator Categorized as SQL Server
When executed against the database of interest, the following T-SQL code will generate a set of SQL statements which, when executed against the same database, will drop every DEFAULT constraint in the database.

select
    sql = 'alter table [dbo].[' + p.name + '] drop constraint [' + o.name + ']'
from
    sys.objects o
    inner join sys.objects p
        on o.parent_object_id = p.object_id
where 1=1
    and o.type = 'D'

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.