﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / SMO/RMO/DMO  / Script difference between two databases / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 17:40:20 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>Thank you!!!!</description><pubDate>Thu, 01 Sep 2011 11:59:49 GMT</pubDate><dc:creator>oughtsix</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>Hi Barry,Can you send me this code? Id love to try it out!ThanksG</description><pubDate>Sun, 03 Jul 2011 23:16:35 GMT</pubDate><dc:creator>Gary Slater</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>Glad I could help, brian.</description><pubDate>Thu, 23 Dec 2010 16:10:50 GMT</pubDate><dc:creator>RBarryYoung</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>I'm not the one who asked for the code, but I used it anyway :-)Worked great.  Thanks!</description><pubDate>Wed, 22 Dec 2010 15:00:35 GMT</pubDate><dc:creator>brian.manlove</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>thulani:  How did this work out for you?</description><pubDate>Sat, 28 Mar 2009 11:44:08 GMT</pubDate><dc:creator>RBarryYoung</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>OK, well  then, the only way that I can see to do it with SMO is through a manual semi-shallow copy, like this:[code="vb"]Imports Microsoft.SqlServerImports Microsoft.SqlServer.ManagementImports Microsoft.SqlServer.Management.CommonImports Microsoft.SqlServer.Management.SmoImports Microsoft.SqlServer.ServerImports system.DataModule Util    Public Sub ColumnDef_Copy(ByVal SourceTable As Smo.Table _            , ByVal TargetTable As Smo.Table _            , ByVal ColName As String)        'copies a column definition from one table to another an then updates the        ' target tables defintion in the database.        '        '2008-05-07 BYoung  Created.        '        'NOTE: untested.        Dim SourceCol As Smo.Column = SourceTable.Columns(ColName)        Dim TargetCol As New Smo.Column(TargetTable, ColName)        'set the target column's properties using a Shallow Copy:        With SourceCol            TargetCol.DataType = .DataType            TargetCol.Collation = .Collation            If .Computed Then                TargetCol.Computed = .Computed                TargetCol.ComputedText = .ComputedText                TargetCol.IsPersisted = .IsPersisted            End If            TargetCol.Default = .Default            TargetCol.DefaultSchema = .DefaultSchema            For Each xp As Smo.ExtendedProperty In .ExtendedProperties                TargetCol.ExtendedProperties.Add( _                    New Smo.ExtendedProperty(TargetCol, xp.Name, xp.Value))            Next            If .Identity Then                TargetCol.Identity = .Identity                TargetCol.IdentityIncrement = .IdentityIncrement                TargetCol.IdentitySeed = .IdentitySeed            End If            TargetCol.NotForReplication = .NotForReplication            TargetCol.Nullable = .Nullable            TargetCol.RowGuidCol = .RowGuidCol            TargetCol.Rule = .Rule            TargetCol.RuleSchema = .RuleSchema        End With        'Find the column's position        Dim ord As Integer = 0        While SourceTable.Columns.Item(ord) IsNot SourceCol            ord += 1        End While        TargetTable.Columns.Add(TargetCol, ord)        TargetTable.Alter()    End SubEnd Module[/code]You will have to test this yourself.</description><pubDate>Fri, 07 Nov 2008 08:08:49 GMT</pubDate><dc:creator>RBarryYoung</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>You can search information_schema.columns in both systems, order by name, and the compare to see which columns are in the tables, or which ones aren't.Then you can use an ALTER TABLE command (or the SMO equivalent) to change the table.I'm not sure why you would put this in an application. Are you changing schema very often or is this just an exercise? The issues are that there could be defaults, rules, constraints, etc. imposed on a column. It's a simple process, but it has a lot of moving parts and it's easy to make mistakes. That's why a tool from someone like Apex or Red Gate is worth a few hundred dollars.</description><pubDate>Fri, 07 Nov 2008 06:46:39 GMT</pubDate><dc:creator>Steve Jones - SSC Editor</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>Sorry for not answering straight.I'm using SMO and vb.net (Even c# can do). I want to loop through the objects of a table then add the column to the other table if it doesn't exist in the other table.</description><pubDate>Fri, 07 Nov 2008 06:10:31 GMT</pubDate><dc:creator>thulani.moyana</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>OK, since you did not say "Yes" to SMO, I am going to assume that SQL script is OK.Is the column at the end or in the middle of the column list?  And is it involved in any indexes or keys?</description><pubDate>Fri, 07 Nov 2008 06:01:47 GMT</pubDate><dc:creator>RBarryYoung</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>Thanx for the response.Yes, I have an application already but I need to take the exact copy of the column from one database to the other. If I have to set scripting options which options.The resulting databases should be identical schematically.This must be like cloning the column but somehow change the table to which it belongs and add it to that  table and capture the Alter table script to run on the database you want to update.</description><pubDate>Thu, 06 Nov 2008 22:55:46 GMT</pubDate><dc:creator>thulani.moyana</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>Are you asking in this forum because you wanted to know how to do this with client code using SMO?</description><pubDate>Thu, 06 Nov 2008 11:49:17 GMT</pubDate><dc:creator>RBarryYoung</dc:creator></item><item><title>RE: Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>The best idea is to get RedGate SQLCompare or Apex SQL's product I think it is SQLDiff.</description><pubDate>Thu, 06 Nov 2008 10:52:16 GMT</pubDate><dc:creator>  Jack Corbett</dc:creator></item><item><title>Script difference between two databases</title><link>http://www.sqlservercentral.com/Forums/Topic597928-22-1.aspx</link><description>I need to compare two databases and update one of them. Suppose a table "Table A" is available in both databases but some columns are missing in the other table and I want to create an update sql script to update one database.I can add columns to the database to update and capture script by changing the execution mode, but the question is:How can I clone the column from one table to the other. I need to add the column as is with all constraints(i.e.) the exact copy of the other column.Any method of scripting the differences such that the resulting script with update the other table or all objects in the other database thus resulting in exactly the same databases.Any help will be appreciated.</description><pubDate>Thu, 06 Nov 2008 00:48:04 GMT</pubDate><dc:creator>thulani.moyana</dc:creator></item></channel></rss>