<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: SQLServer code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 11 Oct 2008 15:22:08 GMT</pubDate>
    <description>DZone Snippets: SQLServer code</description>
    <item>
      <title>Drop an unnamed constraint from SqlServer 2000</title>
      <link>http://snippets.dzone.com/posts/show/5221</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;declare @name nvarchar(32), &lt;br /&gt;    @sql nvarchar(1000)&lt;br /&gt;&lt;br /&gt;-- find constraint name&lt;br /&gt;select @name = O.name &lt;br /&gt;from sysobjects AS O&lt;br /&gt;left join sysobjects AS T&lt;br /&gt;    on O.parent_obj = T.id&lt;br /&gt;where isnull(objectproperty(O.id,'IsMSShipped'),1) = 0&lt;br /&gt;    and O.name not like '%dtproper%'&lt;br /&gt;    and O.name not like 'dt[_]%'&lt;br /&gt;    and T.name = 'MyTable'&lt;br /&gt;    and O.name like 'DF__MyTable__MyColu%'&lt;br /&gt;&lt;br /&gt;-- delete if found&lt;br /&gt;if not @name is null&lt;br /&gt;begin&lt;br /&gt;    select @sql = 'ALTER TABLE [MyTable] DROP CONSTRAINT [' + @name + ']'&lt;br /&gt;    execute sp_executesql @sql&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;-- do your ALTER TABLE here&lt;br /&gt;&lt;br /&gt;-- replace the constraint&lt;br /&gt;select @sql = 'ALTER TABLE [MyTable] ADD CONSTRAINT [' + @name + '] DEFAULT (0) FOR [MyColumn]'&lt;br /&gt;execute sp_executesql @sql&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Mar 2008 22:00:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5221</guid>
      <author>frost137 (Douglas Wyatt)</author>
    </item>
  </channel>
</rss>
