/// <summary> /// Gets the view creation command /// </summary> /// <param name="View">The view object</param> /// <returns>The string creating the view</returns> private static string GetViewCommand(View View) { string Definition = Regex.Replace(View.Definition, "-- (.*)", ""); return Definition.Replace("\n", " ").Replace("\r", " ") + "\n"; }
/// <summary> /// Gets a list of alter commands for a view /// </summary> /// <param name="View">Desired view structure</param> /// <param name="CurrentView">Current view structure</param> /// <returns>A list of commands in a string</returns> private static string GetAlterViewCommand(View View, View CurrentView) { StringBuilder Builder = new StringBuilder(); if (View.Definition != CurrentView.Definition) { Builder.Append("EXEC dbo.sp_executesql @statement = N'DROP VIEW ").Append(View.Name).Append("'\n"); Builder.Append(GetViewCommand(View)); } return Builder.ToString(); }