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_2606200322052335090) AS Schema_Name
FROM master.sys.objects;


            
        

Parameters (If used)

Name Value
@pMAIN_2606200322052335090 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_2606200322052810500), @pMAIN_2606200322052810501, QUOTENAME(OBJECT_SCHEMA_NAME(object_id, DB_ID()), @pMAIN_2606200322052810502), @pMAIN_2606200322052810503, QUOTENAME(OBJECT_NAME(object_id, DB_ID()), @pMAIN_2606200322052810504)) AS Full_Name
FROM sys.objects;


            
        

Parameters (If used)

Name Value
@pMAIN_2606200322052810500 [
@pMAIN_2606200322052810501 .
@pMAIN_2606200322052810502 [
@pMAIN_2606200322052810503 .
@pMAIN_2606200322052810504 [

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