Metadata OBJECT_SCHEMA_NAME SQL function


1. Usage of OBJECT_SCHEMA_NAME

SQL Server Query 1

            
 SELECT DISTINCT OBJECT_SCHEMA_NAME(object_id) AS Schema_Name   
FROM master.sys.objects
UNION ALL
SELECT DISTINCT OBJECT_SCHEMA_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_SCHEMA_NAME(new Column("object_id")), "Schema_Name")
.From("master.sys.objects")
.UnionAll(new SqlQueryBuilder()
.Select().Distinct()
.Column(new OBJECT_SCHEMA_NAME(new Column("object_id"), 1), "Schema_Name")
.From("master.sys.objects")
)
.Build();

Query build by SqlQueryBuilder 1

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


            
        

Parameters (If used)

Name Value
@pMAIN_2608060517386428680 1

Query Results 1:

  Schema_Name
1
2 dbo


2. Usage of OBJECT_SCHEMA_NAME in WHERE clause

SQL Server Query 2

            
 SELECT QUOTENAME(DB_NAME(db_id()))     
+ N'.'
+ QUOTENAME(OBJECT_SCHEMA_NAME(object_id, 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_SCHEMA_NAME(new Column("object_id"), 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_2608060517386890160), @pMAIN_2608060517386890161, QUOTENAME(OBJECT_SCHEMA_NAME(object_id, DB_ID()), @pMAIN_2608060517386890162), @pMAIN_2608060517386890163, QUOTENAME(OBJECT_NAME(object_id, DB_ID()), @pMAIN_2608060517386890164)) AS Full_Name
FROM sys.objects;


            
        

Parameters (If used)

Name Value
@pMAIN_2608060517386890160 [
@pMAIN_2608060517386890161 .
@pMAIN_2608060517386890162 [
@pMAIN_2608060517386890163 .
@pMAIN_2608060517386890164 [

Query Results 2:

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