Search results matching tags 'Administration', 'T-SQL', and 'Tips'http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&tag=Administration,T-SQL,Tips&orTags=0Search results matching tags 'Administration', 'T-SQL', and 'Tips'en-USCommunityServer 2.1 SP2 (Build: 61129.1)System Variables, Stored Procedures or Functions for Meta Datahttp://sqlblog.com/blogs/buck_woody/archive/2010/03/11/system-variables-stored-procedures-or-functions-for-meta-data.aspxThu, 11 Mar 2010 13:42:22 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:23190BuckWoody<p>Whenever you want to know something about SQL Server’s configuration, whether that’s the Instance itself or a database, you have a few options.</p> <p>If you want to know “dynamic” data, such as how much memory or CPU is consumed or what a particular query is doing, you should be using the Dynamic Management Views (DMVs) that you can read about here: <a href="http://msdn.microsoft.com/en-us/library/ms188754.aspx">http://msdn.microsoft.com/en-us/library/ms188754.aspx</a>&#160;</p> <p>But if you’re looking for how much memory is installed on the server, the version of the Instance, the drive letters of the backups and so on, you have other choices.</p> <p>The first of these are system variables. You access these with a SELECT statement, and they are useful when you need a discrete value for use, say in another query or to put into a table. You can read more about those here: <a href="http://msdn.microsoft.com/en-us/library/ms173823.aspx">http://msdn.microsoft.com/en-us/library/ms173823.aspx</a></p> <p>You also have a few stored procedures you can use. These often bring back a lot more data, pre-formatted for the screen. You access these with the EXECUTE syntax. It is a bit more difficult to take the data they return and get a single value or place the results in another table, but it is possible. You can read more about those here: <a href="http://msdn.microsoft.com/en-us/library/ms187961.aspx">http://msdn.microsoft.com/en-us/library/ms187961.aspx</a></p> <p>Yet another option is to use a system function, which you access with a SELECT statement, which also brings back a discrete value that you can use in a test or to place in another table. You can read about those here: <a href="http://msdn.microsoft.com/en-us/library/ms187812.aspx">http://msdn.microsoft.com/en-us/library/ms187812.aspx</a>&#160;</p> <p>By the way, many of these constructs simply query from tables in the <strong>master </strong>or <strong>msdb </strong>databases for the Instance or the <em>system tables</em> in a user database. You can get much of the information there as well, and there are even system views in each database to show you the meta-data dealing with structure – more on that here: <a href="http://msdn.microsoft.com/en-us/library/ms186778.aspx">http://msdn.microsoft.com/en-us/library/ms186778.aspx</a>&#160;</p> <p>Some of these choices are the only way to get at a certain piece of data. But others overlap – you can use one or the other, they both come back with the same data. So, like many Microsoft products, you have multiple ways to do the same thing. And that’s OK – just research what each is used for and how it’s intended to be used, and you’ll be able to select (pun intended) the right choice. </p>