30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

229<br />

Chapter 8: Exploring your Database Schema<br />

some permission on a table then, by implication, that user can also view the metadata<br />

for all the table's subcomponents, such as columns, indexes, check constraints, and<br />

triggers. If the user requests information that he has no permission to see, then a NULL<br />

is returned.<br />

You can mix the Information Schema views with the catalog views and their associated<br />

metadata functions. To return the entire definition of a routine, for example, you can<br />

use the metadata function, Object_Definition(), which is not part of the<br />

Information_Schema standard, as shown in Listing 8-1.<br />

SELECT full_name ,<br />

OBJECT_DEFINITION(OBJECT_ID(full_name))<br />

FROM ( SELECT Routine_SCHEMA + '.' + routine_name AS Full_Name<br />

FROM information_schema.routines<br />

) routines<br />

WHERE full_name LIKE 'MyObjectName'<br />

Listing 8-1: Retrieving object definitions from the INFORMATION_SCHEMA views.<br />

This query won't return information about "non-standard" objects such as triggers, but it<br />

will also miss views (although you can get this information from information_schema.<br />

views). As such, there seems little point in such a query, as the one shown in Listing 8-2,<br />

using the catalog views, will give the same information and also provides information<br />

about triggers, views, and so on.<br />

--find the actual code for a particular stored procedure, view, function etc.<br />

SELECT OBJECT_NAME(object_ID), definition<br />

FROM sys.sql_modules<br />

WHERE OBJECT_NAME(object_ID) = 'MyObjectName'<br />

Listing 8-2: Retrieving object definitions from the system catalog views.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!