Metadata OBJECT_NAME SQL function


1. Usage of OBJECT_NAME

SQL Server Query 1

            
 SELECT DISTINCT OBJECT_NAME(object_id) AS Schema_Name   
FROM master.sys.objects
UNION ALL
SELECT DISTINCT OBJECT_NAME(object_id, 1) AS Schema_Name
FROM master.sys.objects;

Create SQL query with SqlQueryBuilder 1

            
 var (sql1, parameters1) = new SqlQueryBuilder()  
.Select().Distinct()
.Column(new OBJECT_NAME(new Column("object_id")), "Schema_Name")
.From("master.sys.objects")
.UnionAll(new SqlQueryBuilder()
.Select().Distinct()
.Column(new OBJECT_NAME(new Column("object_id"), 1), "Schema_Name")
.From("master.sys.objects")
)
.Build();

Query build by SqlQueryBuilder 1

            
SELECT DISTINCT OBJECT_NAME(object_id) AS Schema_Name
FROM master.sys.objects
UNION ALL
SELECT DISTINCT OBJECT_NAME(object_id, @pMAIN_2608060425108982470) AS Schema_Name
FROM master.sys.objects;


            
        

Parameters (If used)

Name Value
@pMAIN_2608060425108982470 1

Query Results 1:

  Schema_Name
1
2 spt_fallback_db
3 spt_fallback_dev
4 spt_fallback_usg
5 spt_monitor
6 spt_values


2. Usage of OBJECT_NAME

SQL Server Query 2

            
 SELECT QUOTENAME(DB_NAME(db_id()))     
+ N'.'
+ QUOTENAME(OBJECT_NAME(object_id, db_id())) AS Full_Name
FROM sys.objects;

Create SQL query with SqlQueryBuilder 2

            
 var (sql2, parameters2) = new SqlQueryBuilder()  
.Select()
.Column(new CONCAT(new QUOTENAME(new DB_NAME(new DB_ID())),
".",
new QUOTENAME(new OBJECT_NAME(new Column("object_id"), new DB_ID()))), "Full_Name")
.From("sys.objects")
.Build();

Query build by SqlQueryBuilder 2

            
SELECT CONCAT(QUOTENAME(DB_NAME(DB_ID()), @pMAIN_2608060425110389760), @pMAIN_2608060425110389761, QUOTENAME(OBJECT_NAME(object_id, DB_ID()), @pMAIN_2608060425110389762)) AS Full_Name
FROM sys.objects;


            
        

Parameters (If used)

Name Value
@pMAIN_2608060425110389760 [
@pMAIN_2608060425110389761 .
@pMAIN_2608060425110389762 [

Query Results 2:

  Full_Name
1 [TheBlueSoftDB].[PK_Categories]
2 [TheBlueSoftDB].[Countries]
3 [TheBlueSoftDB].[Products]
4 [TheBlueSoftDB].[PK_Countries]
5 [TheBlueSoftDB].[PK_Products]
6 [TheBlueSoftDB].[DF_Countries_EnteredOn]
7 [TheBlueSoftDB].[Alphabetical list of products]
8 [TheBlueSoftDB].[Current Product List]
9 [TheBlueSoftDB].[Course_Master]
10 [TheBlueSoftDB].[Orders]
11 [TheBlueSoftDB].[PK_Course_Master]
12 [TheBlueSoftDB].[PK_Orders]
13 [TheBlueSoftDB].[DF__Countries__IsAct__061CD093]
14 [TheBlueSoftDB].[CustomerProductSalesIndexed]
15 [TheBlueSoftDB].[Tab_Desc]
16 [TheBlueSoftDB].[Orders Qry]
17 [TheBlueSoftDB].[PK_Tab_Desc]
18 [TheBlueSoftDB].[Products Above Average Price]
19 [TheBlueSoftDB].[Tab_Headers]
20 [TheBlueSoftDB].[Products by Category]
21 [TheBlueSoftDB].[PK_Tab_Headers]
22 [TheBlueSoftDB].[Quarterly Orders]
23 [TheBlueSoftDB].[DF_Course_Master_Entered_On]
24 [TheBlueSoftDB].[Employees]
25 [TheBlueSoftDB].[DF_Tab_Desc_Sequence]
26 [TheBlueSoftDB].[PK_Employees]
27 [TheBlueSoftDB].[DF_Tab_Desc_EnteredOn]
28 [TheBlueSoftDB].[Shippers]
29 [TheBlueSoftDB].[DF_Tab_Headers_Sequence]
30 [TheBlueSoftDB].[PK_Shippers]
31 [TheBlueSoftDB].[User_Email_Otps]
32 [TheBlueSoftDB].[user_feedbacks]
33 [TheBlueSoftDB].[DF_Tab_Headers_Entered_On]
34 [TheBlueSoftDB].[Order Details]
35 [TheBlueSoftDB].[DF_User_Email_Otps_Is_Validated]
36 [TheBlueSoftDB].[PK_user_feedbacks]
37 [TheBlueSoftDB].[FK_Tab_Desc_Tab_Headers]
38 [TheBlueSoftDB].[PK_Order_Details]
39 [TheBlueSoftDB].[PK_User_Email_Otps]
40 [TheBlueSoftDB].[DF_user_feedbacks_entered_on]
41 [TheBlueSoftDB].[FK_Tab_Headers_Course_Master]
42 [TheBlueSoftDB].[Invoices]
43 [TheBlueSoftDB].[DF__Course_Ma__Page___11246EEB]
44 [TheBlueSoftDB].[Order Details Extended]
45 [TheBlueSoftDB].[Order Subtotals]
46 [TheBlueSoftDB].[Batch_Master]
47 [TheBlueSoftDB].[Product Sales for 1997]
48 [TheBlueSoftDB].[PK_Batches]
49 [TheBlueSoftDB].[Category Sales for 1997]
50 [TheBlueSoftDB].[Class_Master]
51 [TheBlueSoftDB].[Sales by Category]
52 [TheBlueSoftDB].[PK_Class_Master]
53 [TheBlueSoftDB].[Sales Totals by Amount]
54 [TheBlueSoftDB].[Summary of Sales by Quarter]
55 [TheBlueSoftDB].[Summary of Sales by Year]
56 [TheBlueSoftDB].[DF_Batches_Is_Active]
57 [TheBlueSoftDB].[CustomerCustomerDemo]
58 [TheBlueSoftDB].[DF_Batches_Entered_On]
59 [TheBlueSoftDB].[OnLine_Links]
60 [TheBlueSoftDB].[CustomerDemographics]
61 [TheBlueSoftDB].[DF_Class_Master_Entered_On]
62 [TheBlueSoftDB].[DF_OnLine_Links_Id]
63 [TheBlueSoftDB].[EmployeeTerritories]
64 [TheBlueSoftDB].[DF_OnLine_Links_Sequence]
65 [TheBlueSoftDB].[Region]
66 [TheBlueSoftDB].[DF_OnLine_Links_Entered_On]
67 [TheBlueSoftDB].[Territories]
68 [TheBlueSoftDB].[PK_OnLine_Links]
69 [TheBlueSoftDB].[PK_CustomerCustomerDemo]
70 [TheBlueSoftDB].[PK_CustomerDemographics]
71 [TheBlueSoftDB].[FK_Batches_Course_Master]
72 [TheBlueSoftDB].[PK_EmployeeTerritories]
73 [TheBlueSoftDB].[FK_Class_Master_Batch_Master]
74 [TheBlueSoftDB].[PK_Region]
75 [TheBlueSoftDB].[PK_Territories]
76 [TheBlueSoftDB].[DF_Order_Details_UnitPrice]
77 [TheBlueSoftDB].[DF_Order_Details_Quantity]
78 [TheBlueSoftDB].[DF_Order_Details_Discount]
79 [TheBlueSoftDB].[User_Mobile_Otps]
80 [TheBlueSoftDB].[DF_Orders_Freight]
81 [TheBlueSoftDB].[DF_User_Mobile_Otps_Id]
82 [TheBlueSoftDB].[DF_Products_UnitPrice]
83 [TheBlueSoftDB].[DF_User_Mobile_Otps_Is_Validated]
84 [TheBlueSoftDB].[DF_Products_UnitsInStock]
85 [TheBlueSoftDB].[DF_Products_UnitsOnOrder]
86 [TheBlueSoftDB].[DF_Products_ReorderLevel]
87 [TheBlueSoftDB].[DF_Products_Discontinued]
88 [TheBlueSoftDB].[FK_CustomerCustomerDemo]
89 [TheBlueSoftDB].[FK_CustomerCustomerDemo_Customers]
90 [TheBlueSoftDB].[FK_Employees_Employees]
91 [TheBlueSoftDB].[FK_EmployeeTerritories_Employees]
92 [TheBlueSoftDB].[FK_EmployeeTerritories_Territories]
93 [TheBlueSoftDB].[FK_Order_Details_Orders]
94 [TheBlueSoftDB].[FK_Order_Details_Products]
95 [TheBlueSoftDB].[FK_Orders_Customers]
96 [TheBlueSoftDB].[FK_Orders_Employees]
97 [TheBlueSoftDB].[FK_Orders_Shippers]
98 [TheBlueSoftDB].[User_Emails]
99 [TheBlueSoftDB].[FK_Products_Categories]
100 [TheBlueSoftDB].[PK_User_Emails]
101 [TheBlueSoftDB].[FK_Products_Suppliers]
102 [TheBlueSoftDB].[DF_User_Emails_Id]
103 [TheBlueSoftDB].[FK_Territories_Region]
104 [TheBlueSoftDB].[DF_User_Emails_Email_Type]
105 [TheBlueSoftDB].[CK_Birthdate]
106 [TheBlueSoftDB].[DF_User_Emails_Sent]
107 [TheBlueSoftDB].[CK_Discount]
108 [TheBlueSoftDB].[DF_User_Emails_Entered_On]
109 [TheBlueSoftDB].[CK_Quantity]
110 [TheBlueSoftDB].[CK_UnitPrice]
111 [TheBlueSoftDB].[CK_Products_UnitPrice]
112 [TheBlueSoftDB].[CK_ReorderLevel]
113 [TheBlueSoftDB].[CK_UnitsInStock]
114 [TheBlueSoftDB].[CK_UnitsOnOrder]
115 [TheBlueSoftDB].[CustOrderHist]
116 [TheBlueSoftDB].[CustOrdersDetail]
117 [TheBlueSoftDB].[CustOrdersOrders]
118 [TheBlueSoftDB].[Employee Sales by Country]
119 [TheBlueSoftDB].[Sales by Year]
120 [TheBlueSoftDB].[SalesByCategory]
121 [TheBlueSoftDB].[Ten Most Expensive Products]
122 [TheBlueSoftDB].[User_Registrations]
123 [TheBlueSoftDB].[DF_User_Registrations_Is_Registered]
124 [TheBlueSoftDB].[DF_User_Registrations_Is_Payment_Done]
125 [TheBlueSoftDB].[DF_User_Registrations_Is_Active]
126 [TheBlueSoftDB].[Page_Banners]
127 [TheBlueSoftDB].[DF_User_Registrations_Entered_On]
128 [TheBlueSoftDB].[PK_Page_Banners]
129 [TheBlueSoftDB].[DF_User_Registrations_Failed_Tried]
130 [TheBlueSoftDB].[DF_Page_Banners_IsActive]
131 [TheBlueSoftDB].[PK_User_Registrations]
132 [TheBlueSoftDB].[FK_Page_Banners_Course_Master]
133 [TheBlueSoftDB].[FK_User_Registrations_Class_Master]
134 [TheBlueSoftDB].[Customer and Suppliers by City]
135 [TheBlueSoftDB].[Ten Most Expensive Products]
136 [TheBlueSoftDB].[Employee Sales by Country]
137 [TheBlueSoftDB].[Sales by Year]
138 [TheBlueSoftDB].[CustOrdersDetail]
139 [TheBlueSoftDB].[Razor_Payment_Logs]
140 [TheBlueSoftDB].[Course_Inner_Desc]
141 [TheBlueSoftDB].[CustOrdersOrders]
142 [TheBlueSoftDB].[DF_Razor_Payment_Logs_Id]
143 [TheBlueSoftDB].[PK_Course_Inner_Desc]
144 [TheBlueSoftDB].[States]
145 [TheBlueSoftDB].[CustOrderHist]
146 [TheBlueSoftDB].[DF_Razor_Payment_Logs_Entered_On]
147 [TheBlueSoftDB].[FK_Course_Inner_Desc_Course_Master]
148 [TheBlueSoftDB].[DF_States_EnteredOn]
149 [TheBlueSoftDB].[SalesByCategory]
150 [TheBlueSoftDB].[PK_Razor_Payment_Logs]
151 [TheBlueSoftDB].[DF_Course_Inner_Desc_Sequence]
152 [TheBlueSoftDB].[DF__States__IsActive__0710F4CC]
153 [TheBlueSoftDB].[DF_Course_Inner_Desc_Is_Active]
154 [TheBlueSoftDB].[PK_States]
155 [TheBlueSoftDB].[DF_Page_Banners_Sequence]
156 [TheBlueSoftDB].[FK_User_Registrations_States]
157 [TheBlueSoftDB].[Payment_Tracker]
158 [TheBlueSoftDB].[DF_Payment_Tracker_Payment_Tracking_Id]
159 [TheBlueSoftDB].[DF_Payment_Tracker_Payment_Gateway]
160 [TheBlueSoftDB].[DF_Payment_Tracker_Payment_Status]
161 [TheBlueSoftDB].[DF_Payment_Tracker_Entered_On]
162 [TheBlueSoftDB].[PK_Payment_Tracker]
163 [TheBlueSoftDB].[FK_Payment_Tracker_User_Registrations]
164 [TheBlueSoftDB].[sp_Employees_Insert]
165 [TheBlueSoftDB].[sp_Employees_Update]
166 [TheBlueSoftDB].[LinkedInMediaQueue]
167 [TheBlueSoftDB].[sp_Employees_SelectAll]
168 [TheBlueSoftDB].[PK__LinkedIn__3214EC0722DC852F]
169 [TheBlueSoftDB].[sp_Employees_SelectRow]
170 [TheBlueSoftDB].[DF__LinkedInM__IsPub__69AB7A6E]
171 [TheBlueSoftDB].[DateOnly]
172 [TheBlueSoftDB].[MyRound]
173 [TheBlueSoftDB].[sp_Employees_Cursor]
174 [TheBlueSoftDB].[sp_employees_rownum]
175 [TheBlueSoftDB].[sp_employees_rank]
176 [TheBlueSoftDB].[sp_employees_rollup]
177 [TheBlueSoftDB].[WebTrafficLog]
178 [TheBlueSoftDB].[PK__WebTraff__5E5499A822349522]
179 [TheBlueSoftDB].[v_WebTrafficAnalysis]
180 [TheBlueSoftDB].[QueryNotificationErrorsQueue]
181 [TheBlueSoftDB].[queue_messages_1977058079]
182 [TheBlueSoftDB].[EventNotificationErrorsQueue]
183 [TheBlueSoftDB].[queue_messages_2009058193]
184 [TheBlueSoftDB].[ServiceBrokerQueue]
185 [TheBlueSoftDB].[Customers]
186 [TheBlueSoftDB].[queue_messages_2041058307]
187 [TheBlueSoftDB].[PK_Customers]
188 [TheBlueSoftDB].[Suppliers]
189 [TheBlueSoftDB].[PK_Suppliers]
190 [TheBlueSoftDB].[Customer and Suppliers by City]
191 [TheBlueSoftDB].[Categories]


3. Usage of OBJECT_NAME in WHERE clause

SQL Server Query 3

            
 SELECT name AS Name, object_id AS Object_ID, type_desc AS Type_Desc  
FROM sys.objects
WHERE name = OBJECT_NAME(7);

Create SQL query with SqlQueryBuilder 3

            
 var (sql3, parameters3) = new SqlQueryBuilder()  
.Select()
.Column("name", "Name")
.Column("object_id", "Object_ID")
.Column("type_desc", "Type_Desc")
.From("sys.objects")
.Where(new Where(new Column("name").Equale(new OBJECT_NAME(7))))
.Build();

Query build by SqlQueryBuilder 3

            
SELECT name AS Name,
       object_id AS Object_ID,
       type_desc AS Type_Desc
FROM sys.objects
WHERE name = OBJECT_NAME(@pMAIN_2608060425111864580);


            
        

Parameters (If used)

Name Value
@pMAIN_2608060425111864580 7

Query Results 3:

  Name Object_ID Type_Desc