Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the script to a database view

I lost the script for a view that I created. Can I retrieve / recreate the script from the database using management studio?

like image 766
MedicineMan Avatar asked Nov 05 '10 22:11

MedicineMan


People also ask

How do I add a script to a database?

Right-click the SQL connection and then click Insert Script Files. The Open dialog box opens. 4. Select the SQL script file (.

How do I get all view scripts in SQL Server?

With the Views node highlighted in Object Explorer, open Object Explorer Details ( F8 or Shift + F8 if I recall correctly). This will open a window with all the views in a list, and you highlight the views you want and right-click > script.


1 Answers

You can also retrieve this information by querying the sys.sql_modules dynamic management view:

Here's an example:

USE AdventureWorks
GO
SELECT DEFINITION
  FROM sys.sql_modules  
 WHERE object_id = OBJECT_ID('HumanResources.vEmployee')
like image 148
DataWriter Avatar answered Oct 12 '22 12:10

DataWriter