当前位置: 首页>>代码示例>>C#>>正文


C# Table.Script方法代码示例

本文整理汇总了C#中Table.Script方法的典型用法代码示例。如果您正苦于以下问题:C# Table.Script方法的具体用法?C# Table.Script怎么用?C# Table.Script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Table的用法示例。


在下文中一共展示了Table.Script方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBackupTable

 private static string CreateBackupTable(IDataBase db, Table table)
 {
     var script = Base.JoinScriptFragments(table.Script(new ScriptingOptions {DriPrimaryKey = false, Statistics = false}));
     var scriptForBackupTable = TransformCreationScriptForBackup(script, table.Name);
     db.ExecuteNonQuery(scriptForBackupTable);
     return Analyst.GetBackupTableName(table.Name);
 }
开发者ID:raoulmillais,项目名称:DatabaseMigraine,代码行数:7,代码来源:Bisector.cs

示例2: ScriptTable

        private void ScriptTable(bool verbose, Database db, ScriptingOptions so, string tables, Table table, string triggers, string fullTextIndexes, string foreignKeys, string constraints)
        {
            string fileName = Path.Combine(tables, GetScriptFileName(table));

            #region Table Definition

            using (StreamWriter sw = GetStreamWriter(fileName, false))
            {
                if (verbose) Console.Error.WriteLine("[{0}].[{1}].[{2}]", db.Name, table.Schema, table.Name);
                if (!CreateOnly)
                {
                    so.ScriptDrops = so.IncludeIfNotExists = true;
                    WriteScript(table.Script(so), sw);
                }
                so.ScriptDrops = so.IncludeIfNotExists = false;
                WriteScript(table.Script(so), sw);

                if (Properties)
                {
                    ScriptProperties(table, sw);
                }
            }

            #endregion

            #region Triggers

            foreach (Trigger smo in table.Triggers)
            {
                if ((IncludeSystemObjects || !smo.IsSystemObject) && !smo.IsEncrypted)
                {
                    if (!TableOneFile)
                        fileName = Path.Combine(triggers, GetScriptFileName(table, smo));
                    using (StreamWriter sw = GetStreamWriter(fileName, TableOneFile))
                    {
                        if (verbose) Console.Error.WriteLine("[{0}].[{1}].[{2}]: [{3}]", db.Name, table.Schema, table.Name, smo.Name);
                        if (!CreateOnly)
                        {
                            so.ScriptDrops = so.IncludeIfNotExists = true;
                            WriteScript(smo.Script(so), sw);
                        }
                        so.ScriptDrops = so.IncludeIfNotExists = false;
                        WriteScript(smo.Script(so), sw);

                        if (Properties)
                        {
                            ScriptProperties(smo, sw);
                        }
                    }
                }
            }

            #endregion

            ScriptIndexes(table, verbose, db, so, tables);

            #region Full Text Indexes

            if (table.FullTextIndex != null)
            {
                if (!TableOneFile)
                    fileName = Path.Combine(fullTextIndexes, GetScriptFileName(table));
                using (StreamWriter sw = GetStreamWriter(fileName, TableOneFile))
                {
                    if (verbose) Console.Error.WriteLine("[{0}].[{1}].[{2}]: full-text index", db.Name, table.Schema, table.Name);
                    if (!CreateOnly)
                    {
                        so.ScriptDrops = so.IncludeIfNotExists = true;
                        WriteScript(table.FullTextIndex.Script(so), sw);
                    }
                    so.ScriptDrops = so.IncludeIfNotExists = false;
                    WriteScript(table.FullTextIndex.Script(so), sw);
                }
            }

            #endregion

            #region Foreign Keys

            foreach (ForeignKey smo in table.ForeignKeys)
            {
                if (!TableOneFile)
                    fileName = Path.Combine(foreignKeys, GetScriptFileName(table, smo));
                using (StreamWriter sw = GetStreamWriter(fileName, TableOneFile))
                {
                    if (verbose) Console.Error.WriteLine("[{0}].[{1}].[{2}]: [{3}]", db.Name, table.Schema, table.Name, smo.Name);
                    if (!CreateOnly)
                    {
                        so.ScriptDrops = so.IncludeIfNotExists = true;
                    }
                    WriteScript(smo.Script(), sw);

                    if (Properties)
                    {
                        ScriptProperties(smo, sw);
                    }
                }
            }

            #endregion
//.........这里部分代码省略.........
开发者ID:bhank,项目名称:ScriptDB,代码行数:101,代码来源:DatabaseScripter.cs

示例3: scripttable

        //生成表脚本的方法
        private void scripttable(Table tb)
        {
            string ids;
            Table table = new Table();
            if (reftables.Contains(tb.Name))
                return;

            //对外键表编写脚本
            foreach (ForeignKey fk in tb.ForeignKeys)
            {
                //迭代算法

                foreach (Table temptb in db.Tables)
                {
                    if (temptb.Name == fk.ReferencedTable)
                    {
                        table = temptb;
                        break;
                    }
                }

                if (table.Name != tb.Name)
                {
                    scripttable(table);
                }
            }

            //编写本表的的脚本
            stroutput = new StringBuilder();

            stroutput.AppendLine();
            stroutput.AppendLine("--表[" + tb.Name + "]脚本");

            strColl = tb.Script(scpopt);

            foreach (String str in strColl)
            {
                //此处修正smo的bug
                if (str.Contains("ADD  DEFAULT") && str.Contains("') AND type = 'D'"))
                {
                    ids = str.Substring(str.IndexOf("OBJECT_ID(N'") + "OBJECT_ID(N'".Length, str.IndexOf("') AND type = 'D'") - str.IndexOf("OBJECT_ID(N'") - "OBJECT_ID(N'".Length);
                    stroutput.AppendLine(str.Insert(str.IndexOf("ADD  DEFAULT") + 4, "CONSTRAINT " + ids));
                }
                else
                    stroutput.AppendLine(str);

                stroutput.AppendLine("GO");
            }
            output.AppendText(stroutput.ToString());
            SaveFile(stroutput.ToString(), txtSaveDir.Text + "\\" + svr.Name.Replace(",7001", string.Empty) + "_" + db.Name + ".tab");
            stroutput = new StringBuilder();

            //将编写完的表写入已完成表集合内
            reftables.Add(tb.Name);
        }
开发者ID:tebbic,项目名称:SMO,代码行数:56,代码来源:main.cs

示例4: WriteTableSchemaScript

        protected virtual void WriteTableSchemaScript(Table table)
        {
            Throw.If(table).IsNull();

            if (!exportParams.ScriptTableSchema)
                return;

            string sql = table.Script().ToSqlString();

            writer.WriteTableScript(table.Name, sql);
            UpdateProgress(table.Name);
        }
开发者ID:sneal,项目名称:SqlServerExporter,代码行数:12,代码来源:ScriptEngine.cs


注:本文中的Table.Script方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。