0

If I select 'edit' in SS2005 management studio express, I am given a T-SQL 'Alter View' expression that, as given, describes the existing view. I can edit the expression and use it to alter the view.

Is there any other way of getting that T-SQL script?

As described here: Is there a way to retrieve the view definition from a SQL Server using plain ADO? sys.sql_modules and syscomments.text both provide only a historical 'create' script which may or may not be the same as the view as it exists today: it's common to find that the 'create' script creates a view with a different name.

david
  • 2,435
  • 1
  • 21
  • 33
  • Won't help you, but I have to point out that all your source code should be in source control. I presume that's why you are needing to pull out from database to add to source control? – Mitch Wheat Dec 02 '19 at 02:36
  • The only difference in the view definition text in `sys.sql_modules` might be the name, and only if it was renamed. SMO (not a T-SQL solution) fixes the name when scripted. – Dan Guzman Dec 02 '19 at 02:59
  • It should not be too difficult to come up with string searching/parsing code (in tSQL) that would search for `CREATE / ALTER VIEW` in sys.sql_modules and grab the name, then compare it to the actual view name. @DanGuzman suggestion is IMO better. – Alex Dec 02 '19 at 12:10

0 Answers0