Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

SQLStudies

My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.

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


Comments

Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...