Exemple #1
0
        internal static string CreateGetDatabaseNamesBasedOnFileNameScript(
            string databaseFileName,
            bool useDeprecatedSystemTable)
        {
            SqlDdlBuilder builder = new SqlDdlBuilder();

            builder.AppendSql("SELECT [d].[name] FROM ");
            SqlDdlBuilder.AppendSysDatabases(builder, useDeprecatedSystemTable);
            builder.AppendSql(" AS [d] ");
            if (!useDeprecatedSystemTable)
            {
                builder.AppendSql("INNER JOIN sys.master_files AS [f] ON [f].[database_id] = [d].[database_id]");
            }
            builder.AppendSql(" WHERE [");
            if (useDeprecatedSystemTable)
            {
                builder.AppendSql("filename");
            }
            else
            {
                builder.AppendSql("f].[physical_name");
            }
            builder.AppendSql("]=");
            builder.AppendStringLiteral(databaseFileName);
            return(builder.unencodedStringBuilder.ToString());
        }