When I am not writing the blog posts, I spend most of the time helping clients with Comprehensive Database Performance Health Check. One of the epic challenges, I have when I am working with my client is that quite often I am not able to figure out if the object, I am working with is a table or view. Let us learn how I use a quick trick to know the object property with the keyword OBJECTPROPERTY.
Let us assume that I have a table called Sales.Invoices from database WideWorldImporters. Let us use the function OBJECTPROPERTY to figure out if it is a view or table.
SELECT OBJECTPROPERTY(OBJECT_ID(N'Sales.Invoices'), 'IsTable') IsTable, OBJECTPROPERTY(OBJECT_ID(N'Sales.Invoices'), 'IsView') IsView
When you run the script above you will get the following result.
As you can see, I can easily figure out the object property with the function. Personally, I use this function for quite a lot of things during my consultancy engagement. Let me know if you are interested to know more about this topic and I will write more blogs as well as create an SQL in Sixty Seconds video.
Here are my few recent videos and I would like to know what is your feedback about them.
- Find Expensive Queries – SQL in Sixty Seconds #159
- Case-Sensitive Search – SQL in Sixty Seconds #158
- Wait Stats for Performance – SQL in Sixty Seconds #157
- Multiple Backup Copies Stripped – SQL in Sixty Seconds #156
Reference: Pinal Dave (https://blog.sqlauthority.com)