Blog Post

fn_OBJECT_TYPE

,

I recently started using OBJECT_NAME, OBJECT_SCHEMA_NAME and OBJECT_ID functions; unfortunately I really could have used OBJECT_TYPE but it doesn’t exist (yet?). So for now I wrote one of my own.

FYI I originally wrote it as sp_ and created it in the master db thinking that this would cause it to be available from any database. Unfortunately it appears that this doesn’t work for functions, only stored procedures, views and would you believe tables? I’d love it if someone would explain that one to me sometime.

CREATE FUNCTION dbo.fn_OBJECT_TYPE (@Object_Id INT) 
RETURNS nvarchar
AS
BEGIN
DECLARE @type_desc nvarchar(120)
SELECT @type_desc = type_desc
FROM sys.all_objects
WHERE object_id = @Object_Id
RETURN @type_desc
END
GO

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating