<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Louis Davidson : System Functions</title><link>http://sqlblog.com/blogs/louis_davidson/archive/tags/System+Functions/default.aspx</link><description>Tags: System Functions</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>There is still stuff I hadn't noticed (OBJECT_ID has a parameter for type of object)</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2006/12/03/there-is-still-stuff-i-hadn-t-noticed-object-id-has-a-parameter-for-type-of-object.aspx</link><pubDate>Sun, 03 Dec 2006 21:42:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:398</guid><dc:creator>drsql</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/398.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=398</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=398</wfw:comment><description>&lt;P&gt;I was building a script to build a table I had built in my dev environment including inserts so I did a bit of hunting around and came upon Vyas's script (&lt;A title=http://vyaskn.tripod.com/ href="http://vyaskn.tripod.com/"&gt;&lt;FONT color=#669966&gt;http://vyaskn.tripod.com/&lt;/FONT&gt;&lt;/A&gt;) that is used to generate inserts from a table (script here: &lt;A title=http://vyaskn.tripod.com/code/generate_inserts_2005.txt href="http://vyaskn.tripod.com/code/generate_inserts_2005.txt"&gt;&lt;FONT color=#669966&gt;http://vyaskn.tripod.com/code/generate_inserts_2005.txt&lt;/FONT&gt;&lt;/A&gt;).&amp;nbsp; Very cool stuff and worked nicely (all I did was specify a table.)&lt;/P&gt;
&lt;P&gt;What was really interesting was that his drop or create batch to start the script looked like this:&lt;/P&gt;
&lt;P&gt;IF (SELECT OBJECT_ID('sp_generate_inserts','P')) IS NOT NULL --means, the procedure already exists&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp; BEGIN &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRINT 'Procedure already exists. So, dropping it' &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DROP PROC sp_generate_inserts &lt;BR&gt;&amp;nbsp;&amp;nbsp; END &lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;Hmmm: OBJECT_ID('sp_generate_inserts','P'))?&amp;nbsp; What is P?&amp;nbsp; Well, looking at BOL it is the type of object!&amp;nbsp; Cool.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;After creating the stored procedure, running the following commands:&lt;/P&gt;
&lt;P&gt;select OBJECT_ID('sp_generate_inserts') &lt;BR&gt;select OBJECT_ID('sp_generate_inserts','P') &lt;BR&gt;select OBJECT_ID('sp_generate_inserts','U')&lt;/P&gt;
&lt;P&gt;Will tell you 1, that there is an object named sp_generate_inserts, it is a procedure, and it is not a table.&amp;nbsp; Very useful.&amp;nbsp; Of course, because a procedure has to be the only thing created in a batch, this information is not tremendously useful in building better scripts.&amp;nbsp; But it is interesting new feature. &lt;/P&gt;
&lt;P&gt;Now, what is really interesting new thing is addition of database_id as a parameter to object_name.&amp;nbsp; But I will talk about that later...&lt;/P&gt;
&lt;P&gt;Crossposted to &lt;A href="http://drsql.spaces.live.com/"&gt;&lt;FONT color=#669966&gt;http://drsql.spaces.live.com&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=398" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/System+Functions/default.aspx">System Functions</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx">T-SQL</category></item><item><title>Easier access to metadata coming soon to a SQL Server near you</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2006/09/25/easier-access-to-metadata-coming-soon-to-a-sql-server-near-you.aspx</link><pubDate>Mon, 25 Sep 2006 23:35:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:250</guid><dc:creator>drsql</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/250.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=250</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=250</wfw:comment><description>&lt;P&gt;This is not a scoop or anything, but it is quite newsworthy.&amp;nbsp; It is also a good way to kick off my sqlblog er...blog:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/kalen_delaney/archive/2006/09/24/245.aspx" target=_blank&gt;Kalen Delaney - Metadata Power&lt;/A&gt;&lt;BR&gt;&lt;A href="http://sqlblogcasts.com/blogs/simons/archive/2006/09/24/object_name___to_be_extended_in_SP2.aspx"&gt;Simon Sabin - object_name() to be extended in SP2&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;A very common request is to have some of the system functions to work in any database.&amp;nbsp; Kalen posted a &lt;A href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=163373" target=_blank&gt;piece of feedback on connect&lt;/A&gt;&amp;nbsp;to allow the object_name function to work with an optional second parameter of database_id!&amp;nbsp; Wow!&amp;nbsp; Thank you thank you!&amp;nbsp; I hope this becomes a standard feature on all of the database specific functions...&lt;/P&gt;
&lt;P&gt;And for those of you who (like me) have started to embrace schemas, they also added a function: object_schema_name that returns the schema_name of the object.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I had also &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=167864"&gt;asked for something like the latter&lt;/A&gt;, but they just closed it and told me to do this:&lt;BR&gt;SCHEMA_NAME(OBJECTPROPERTY(&amp;lt;object_id&amp;gt;, 'schemaid')).&amp;nbsp;&amp;nbsp; Well, I would listen to &lt;A href="http://sqlblog.com/blogs/kalen_delaney/default.aspx" target=_blank&gt;Kalen&lt;/A&gt; over me too :)&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Crossposted on &lt;/EM&gt;&lt;A href="http://drsql.spaces.live.com"&gt;&lt;EM&gt;drsql.spaces.live.com&lt;/EM&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=250" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/System+Functions/default.aspx">System Functions</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx">T-SQL</category></item></channel></rss>