Create tables schema to another database using SMO.
I have created a package which will create table script to your physical path and also executes same thing on another database to create table schema.
#region Namespaces using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; using System.Data.SqlClient; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Collector; using Microsoft.SqlServer.Management.Common; using System.Collections.Specialized; using System.Collections.Generic; #endregion namespace ST_ab378c7f30204c94a2f49a2b0f7ac500 { [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute] public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase { public void Main() { try { string TableName; TableName = (Dts.Variables["User::TableName"].Value.ToString()); Server server = new Server(); Database source_database = new Database(); Database destination_database = new Database(); server.ConnectionContext.LoginSecure = false; server.ConnectionContext.Login = "sa"; server.ConnectionContext.Password = "reliancesp"; server.ConnectionContext.ServerInstance = "User8\\SQL"; source_database = server.Databases["Adventureworks2012"]; destination_database = server.Databases["ReceiverDB"]; Table table = source_database.Tables[TableName]; string tables = table.Name.ToString(); //Define properties in scriptingOptions ScriptingOptions scriptingOptions = new ScriptingOptions(); scriptingOptions.ClusteredIndexes = true; scriptingOptions.NonClusteredIndexes = true; scriptingOptions.Default = true; scriptingOptions.DriAll = true; scriptingOptions.Indexes = true; scriptingOptions.IncludeHeaders = true; scriptingOptions.ScriptSchema = true; scriptingOptions.ScriptDrops = false; scriptingOptions.Triggers = true; StringCollection result = table.Script(scriptingOptions); var script = ""; foreach (var line in result) { script += line + "\r\n"; } System.IO.StreamWriter fs = System.IO.File.CreateText(@"D:\data\" + TableName + ".sql"); fs.Write(script); fs.Close(); destination_database.ExecuteNonQuery(script); } catch(Exception e) { MessageBox.Show(e.Message.ToString()); } Dts.TaskResult = (int)ScriptResults.Success; } #region ScriptResults declaration /// <summary> /// This enum provides a convenient shorthand within the scope of this class for setting the /// result of the script. /// /// This code was generated automatically. /// </summary> enum ScriptResults { Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure }; #endregion } }