<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Two ways to find / drop a default constraint without knowing its name</title><link>http://msmvps.com/blogs/robfarley/archive/2007/11/26/two-ways-to-find-drop-a-default-constraint-without-knowing-its-name.aspx</link><description>So suppose you&amp;#39;ve created a default constraint without specifying the name (on a SQL Server 2005 machine). You do know the table and column, of course - you just don&amp;#39;t have the name of the default constraint. Now you want to find the name so that</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Drop a default constraint without knowing the name &amp;laquo; Technical Aspects in IT</title><link>http://msmvps.com/blogs/robfarley/archive/2007/11/26/two-ways-to-find-drop-a-default-constraint-without-knowing-its-name.aspx#1658611</link><pubDate>Tue, 06 Jan 2009 05:48:02 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1658611</guid><dc:creator>Drop a default constraint without knowing the name « Technical Aspects in IT</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;Drop a default constraint without knowing the name &amp;laquo; Technical Aspects in IT&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1658611" width="1" height="1"&gt;</description></item><item><title>re: Two ways to find / drop a default constraint without knowing its name</title><link>http://msmvps.com/blogs/robfarley/archive/2007/11/26/two-ways-to-find-drop-a-default-constraint-without-knowing-its-name.aspx#1364748</link><pubDate>Wed, 28 Nov 2007 07:42:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1364748</guid><dc:creator>Rob Farley</dc:creator><description>&lt;p&gt;Ah, nice tip. Thanks Darren.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1364748" width="1" height="1"&gt;</description></item><item><title>re: Two ways to find / drop a default constraint without knowing its name</title><link>http://msmvps.com/blogs/robfarley/archive/2007/11/26/two-ways-to-find-drop-a-default-constraint-without-knowing-its-name.aspx#1361072</link><pubDate>Tue, 27 Nov 2007 10:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1361072</guid><dc:creator>Darren Gosbell</dc:creator><description>&lt;p&gt;The schema is the issue with the powershell script. I thought I would have been able to pipe the Tables collection to get-member to see it's methods, but PowerShell was too smart and pulled out the first table so I ended up using reflector to find out that the TableCollection class has an Item() method which has an overload that takes 2 strings, the name and the schema.&lt;/p&gt;
&lt;p&gt;So the following should work.&lt;/p&gt;
&lt;p&gt;[reflection.assembly]::LoadwithPartialName(&amp;quot;Microsoft.SQLServer.SMO&amp;quot;)&lt;/p&gt;
&lt;p&gt;$sql = New-Object 'Microsoft.sqlserver.management.smo.server' 'localhost'&lt;/p&gt;
&lt;p&gt;$sql.Databases[&amp;quot;AdventureWorks&amp;quot;].Tables.Item(&amp;quot;Department&amp;quot;,&amp;quot;HumanResources&amp;quot;).Columns[&amp;quot;ModifiedDate&amp;quot;].DefaultConstraint.Drop()&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1361072" width="1" height="1"&gt;</description></item></channel></rss>