Skip to content

SqlSkull

SQL Server | SSRS | SSIS | Power BI | DAX
  • Home
  • About Us
  • Microsoft SQL Server
    • SQL Basics Concepts
    • SQL Advance Concepts
    • SQL Interview Q & A
    • SQL Server Tricks & Tips
  • SSRS
  • SSIS
  • POWER BI
  • Python with ML
  • Microsoft Azure
  • HTML Color picker

SqlSkull

SQL Server | SSRS | SSIS | Power BI | DAX
  • Home
  • About Us
  • Microsoft SQL Server
    • SQL Basics Concepts
    • SQL Advance Concepts
    • SQL Interview Q & A
    • SQL Server Tricks & Tips
  • SSRS
  • SSIS
  • POWER BI
  • Python with ML
  • Microsoft Azure
  • HTML Color picker
Home » Object_Id Metadata Function

Object_Id Metadata Function

  • by Pradeep Raturi
  • SQL Advance, SQL SERVER

Object_ID is a SQL Server Metadata function which returns the database object identification number of a schema-scoped object.



  • It can not be used for object that are not schema-scoped such as DDL triggers.
  • If any error occurred it returns null.

SYNTAX

OBJECT_ID ( 'database_name . schema_name . object_name' )

Object_name is the name of object to be used.

database_name and schema_name is the database and schema name of specified object.  Specifying database name and schema name is an optional.

Lets look at an example of using OBJECT_ID function in SQL Server.

Using OBJECT_ID function

Following T-SQL Query, uses the OBJECT_ID metadata function and returns object Id of the table Employee in the database AdventureWorks2017.

USE Master; 
GO 
SELECT OBJECT_ID(N'AdventureWorks2017.HumanResources.Employee') AS 'Object ID'; 
GO

You can also remove database name Adventurework2017 from above T-SQL Query,  if the Adventureworks2017 database is already the active database.

Lets remove the database name from from above T-SQL Query as following.

USE AdventureWorks2017; 
GO 
SELECT OBJECT_ID(N'HumanResources.Employee') AS 'Object ID'; 
GO

Checking the existence of Objects in database using OBJECT_ID function

Using OBJECT_ID metadata function, you can check the existence of objects in database such as any table exists in database or not.

Following T-SQL query uses OBJECT_ID metadata function to check the existence of table Employee in database Adventureworks2017.

USE AdventureWorks2017; 
GO 
IF OBJECT_ID (N'HumanResources.Employee', N'U') IS NOT NULL 
  BEGIN
  SELECT 'Table exits' AS [Status]
  END
ELSE
  BEGIN
  SELECT 'Table does not exist' AS [Status]
  END

You can also verify the object Id returned by OBJECT_ID function in SQL Server system catalog view sys.objects which contains a row for each user-defined, schema-scoped object that is created within a database.



Lets see the details of object Employee whose object Id is 893581784 which is returned by OBJECT_ID function.

SELECT * FROM Sys.Objects 
WHERE OBJECT_ID =1893581784

You can see, using object id you can find more details about object in system catalog view sys.objects.

View all the available Metadata function in SQL Server Management Studio

You can see all the available metadata function in SQL Server using SQL Server Management studio.

Go to Object Explorer, In Database, expand the Programmability after that expand the Functions.

Inside functions you can see the list of available Metadata functions.

Also Read..

PARSENAME

Check if User table or Temp table exists in database

SQL Basics TutorialSQL Advance TutorialSSRSInterview Q & A
SQL Create tableSQL Server Stored ProcedureCreate a New SSRS Project List Of SQL Server basics to Advance Level Interview Q & A
SQL ALTER TABLESQL Server MergeCreate a Shared Data Source in SSRSSQL Server Question & Answer Quiz
SQL DropSQL Server PivotCreate a SSRS Tabular Report / Detail Report
..... More.... More....More
Power BI TutorialAzure TutorialPython TutorialSQL Server Tips & Tricks
Download and Install Power BI DesktopCreate an Azure storage accountLearn Python & ML Step by stepEnable Dark theme in SQL Server Management studio
Connect Power BI to SQL ServerUpload files to Azure storage containerSQL Server Template Explorer
Create Report ToolTip Pages in Power BICreate Azure SQL Database ServerDisplaying line numbers in Query Editor Window
....More....More....More




 1,502 total views,  8 views today

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Reddit (Opens in new window)

Related

Tags:Check if table exists in database or notCheck the existence of tables in Database in SQLChecking the existence of Objects in database using OBJECT_ID functionfind Metadata function in SQL Server Management StudionGet an Object's ID from its Name in SQL ServerHow to check if table exists in database or not?How to get Object Id of table in SQL ServerMetadata function in SQLMetadata function in SSMSOBJECT_ID Function in SQLObject_Id Metadata function in SQLOBJECT_ID() FunctionSQLSQL DatabaseSQL Object Id functionSQL OBJECT_IDSQL Object_Id functionSQL ServerSQL Server In built functionsSQL Server Interview Question and AnswerSQL Server Metadata FunctionsSQL Server TutorialSQL Server Tutorials By Pradeep RaturiSQL TutorialSQL Tutorialssys.objectst-sqlT-SQL Metadata FunctionsT-SQL Object_Id() Metadata FunctionWhat is Object ID SQL?

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

previousDynamic Data Masking in SQL Server
nextImplementing a Table Heat Map in Power BI
Generic selectors
Exact matches only
Search in title
Search in content

SQL Advance

  • SQL Advance
    • SQL Server Stored Procedure
    • How to Encrypt a Stored Procedure in SQL Server
    • Insert the output of a stored procedure into table/temp table
    • SQL Server Stored Procedures Vs User Defined Functions
    • SQL SERVER VIEW
    • SQL Server OUTPUT CLAUSE
    • SQL MERGE
    • SQL Server PIVOT
    • SQL Server Dynamic PIVOT
    • SQL Server UNPIVOT
    • SQL SERVER ROLLUP
    • SQL Server Synonyms
    • SQL Server CUBE
    • SQL Server GROUPING SETS
    • SQL SERVER User Defined Table Type and Table Valued Parameters
    • USER DEFINED FUNCTIONS
    • SQL Server Create SCHEMA
    • SQL Server Sequence
    • SQL Server OFFSET FETCH
    • SQL Server CTE
    • SQL Server Recursive CTE
    • SQL Server Change Data Capture
    • SQL Server TEMPORAL TABLE
    • SQL Server Cursor
    • SQL WAITFOR
    • IDENT_CURRENT Function
    • DROP IF EXISTS
    • SQL ERROR HANDLING WITH TRY..CATCH
    • SQL SERVER IF..ELSE
    • SQL GOTO Statement
    • SQL Server WHILE
    • SQL Return
    • SQL JSON_VALUE Function
    • SQL Server FOR JSON Clause
    • SQL JSON_QUERY Function
    • SQL JSON_MODIFY Function
    • SQL Server FOR XML Clause
    • SQL SERVER SET XACT_ABORT
    • SET STATISTICS IO
    • SQL SET Language
    • SQL SET ROWCOUNT
    • SQL SET NOCOUNT ON
    • SQL SERVER SET IDENTITY_INSERT
    • SQL SERVER SET DATEFORMAT
    • SQL CLUSTERED INDEX
    • Difference between clustered index and non clustered index
    • SQL Triggers
      • SQL DML AFTER TRIGGER
      • SQL DML Instead Of Trigger
      • SQL LOGON Trigger
      • SQL DDL Trigger
    • Get the definitions of Stored procedures, User Defined functions and Triggers in SQL
    • SQL ROLLBACK Transactions
    • SQL Server Dirty Reads in concurrent transactions
    • Lost update problem in concurrent transations
    • Identify Blocked Processes or Long Running Query In SQL Server
    • Schedule a Job in SQL
    • SQL sp_helptext
    • SQL Server sp_procoption startup procedures
    • SQL Server sp_executesql
    • SQL SERVER SP_MONITOR
    • SP_RENAME in SQL Server
    • SQL sp_help
    • How to Read SQL Server error logs using the xp_readerrorlog
    • SQL Server Database Mail Configurations
    • Send a SQL Server query results in e-mail message
    • Troubleshooting Database Mail in SQL Server
    • Import file in SQL server
    • Export data from SQL Server to an Excel file
    • Bulk Insert in SQL Server
    • Copy or delete files from directory in SQL Server
    • Row Level Security in SQL Server
    • Dynamic Data Masking in SQL Server
    • SQL Vulnerability Assessment
    • Column Level Encryption Decryption using Symmetric Keys
    • SQL Data Discovery and Classification
    • Script table in SQL Server
    • Generate Database Scripts With Data in SQL Server
  • SQL Basics Concepts
  • SQL Interview Q & A
  • SQL Server Tricks & Tips
  • SSRS-SQL Server Reporting Services

Page Views

  • 644,506 hits

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Translate this website..

Search for Tutorial

Generic selectors
Exact matches only
Search in title
Search in content
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Home
  • SQL Basics Concepts
  • SQL Advance Concepts
  • SQL Interview Q & A
  • SQL Server Tricks & Tips
  • SSRS-SQL Server Reporting Services
  • SSIS-SQL Server Integration Services
  • POWER BI
  • Python with Machine Learning
  • Microsoft Azure
  • HTML Color picker

SqlSkull. All Rights Reserved

 

Loading Comments...