コード例 #1
0
        public override string ToSql()
        {
            string sql = "";

            if (columns.Count > 0)
            {
                sql += "CREATE TYPE " + FullName + " AS TABLE\r\n(\r\n";
                sql += columns.ToSql() + "\r\n";
                sql += constraints.ToSql();
                sql += ")";
                sql += "\r\nGO\r\n";
            }
            return(sql);
        }
コード例 #2
0
ファイル: Table.cs プロジェクト: ftabangcura/sql-dbdiff
        /// <summary>
        /// Devuelve el schema de la tabla en formato SQL.
        /// </summary>
        public string ToSql(Boolean showFK)
        {
            string sql   = "";
            string sqlPK = "";
            string sqlUC = "";
            string sqlFK = "";

            if (columns.Count > 0)
            {
                sql += "CREATE TABLE " + FullName + "\r\n(\r\n";
                sql += columns.ToSql();
                if (Constraints.Count > 0)
                {
                    sql += ",\r\n";
                    Constraints.ForEach(item =>
                    {
                        if (item.Type == Constraint.ConstraintType.PrimaryKey)
                        {
                            sqlPK += "\t" + item.ToSql() + ",\r\n";
                        }
                        if (item.Type == Constraint.ConstraintType.Unique)
                        {
                            sqlUC += "\t" + item.ToSql() + ",\r\n";
                        }
                        if (showFK)
                        {
                            if (item.Type == Constraint.ConstraintType.ForeignKey)
                            {
                                sqlFK += "\t" + item.ToSql() + ",\r\n";
                            }
                        }
                    });
                    sql += sqlPK + sqlUC + sqlFK;
                    sql  = sql.Substring(0, sql.Length - 3) + "\r\n";
                }
                else
                {
                    sql += "\r\n";
                    if (!String.IsNullOrEmpty(CompressType))
                    {
                        sql += "WITH (DATA_COMPRESSION = " + CompressType + ")\r\n";
                    }
                }
                sql += ")";
                if (!String.IsNullOrEmpty(FileGroup))
                {
                    sql += " ON [" + FileGroup + "]";
                }
                if (!String.IsNullOrEmpty(FileGroupText))
                {
                    if (HasBlobColumn)
                    {
                        sql += " TEXTIMAGE_ON [" + FileGroupText + "]";
                    }
                }
                if ((!String.IsNullOrEmpty(FileGroupStream)) && (HasFileStream))
                {
                    sql += " FILESTREAM_ON [" + FileGroupStream + "]";
                }

                sql += "\r\n";
                sql += "GO\r\n";
                Constraints.ForEach(item =>
                {
                    if (item.Type == Constraint.ConstraintType.Check)
                    {
                        sql += item.ToSqlAdd() + "\r\n";
                    }
                });
                if (HasChangeTracking)
                {
                    sql += ToSqlChangeTracking();
                }
                sql += Indexes.ToSql();
                sql += FullTextIndex.ToSql();
                sql += Options.ToSql();
                sql += Triggers.ToSql();
            }
            return(sql);
        }
コード例 #3
0
        /// <summary>
        /// Devuelve el schema de la tabla en formato SQL.
        /// </summary>
        public string ToSql(Boolean showFK)
        {
            Database    database = null;
            ISchemaBase current  = this;

            while (database == null && current.Parent != null)
            {
                database = current.Parent as Database;
                current  = current.Parent;
            }
            var isAzure10 = database.Info.Version == DatabaseInfo.VersionTypeEnum.SQLServerAzure10;

            string sql   = "";
            string sqlPK = "";
            string sqlUC = "";
            string sqlFK = "";

            if (columns.Count > 0)
            {
                sql += "CREATE TABLE " + FullName + "\r\n(\r\n";
                sql += columns.ToSql();
                if (Constraints.Count > 0)
                {
                    sql += ",\r\n";
                    Constraints.ForEach(item =>
                    {
                        if (item.Type == Constraint.ConstraintType.PrimaryKey)
                        {
                            sqlPK += "\t" + item.ToSql() + ",\r\n";
                        }
                        if (item.Type == Constraint.ConstraintType.Unique)
                        {
                            sqlUC += "\t" + item.ToSql() + ",\r\n";
                        }
                        if (showFK)
                        {
                            if (item.Type == Constraint.ConstraintType.ForeignKey)
                            {
                                sqlFK += "\t" + item.ToSql() + ",\r\n";
                            }
                        }
                    });
                    sql += sqlPK + sqlUC + sqlFK;
                    sql  = sql.Substring(0, sql.Length - 3) + "\r\n";
                }
                else
                {
                    sql += "\r\n";
                    if (!String.IsNullOrEmpty(CompressType))
                    {
                        sql += "WITH (DATA_COMPRESSION = " + CompressType + ")\r\n";
                    }
                }
                sql += ")";

                if (!isAzure10)
                {
                    if (!String.IsNullOrEmpty(FileGroup))
                    {
                        sql += " ON [" + FileGroup + "]";
                    }

                    if (!String.IsNullOrEmpty(FileGroupText))
                    {
                        if (HasBlobColumn)
                        {
                            sql += " TEXTIMAGE_ON [" + FileGroupText + "]";
                        }
                    }
                    if ((!String.IsNullOrEmpty(FileGroupStream)) && (HasFileStream))
                    {
                        sql += " FILESTREAM_ON [" + FileGroupStream + "]";
                    }
                }
                sql += "\r\n";
                sql += "GO\r\n";
                Constraints.ForEach(item =>
                {
                    if (item.Type == Constraint.ConstraintType.Check)
                    {
                        sql += item.ToSqlAdd() + "\r\n";
                    }
                });
                if (HasChangeTracking)
                {
                    sql += ToSqlChangeTracking();
                }
                sql += Indexes.ToSql();
                sql += FullTextIndex.ToSql();
                sql += Options.ToSql();
                sql += Triggers.ToSql();
            }
            return(sql);
        }