By using this website, you agree to our Terms of Use (click here)
If you've never run a SQL statement before, then I've got a great place for you to start. You can start by running this SQL statement:
SELECT * FROM Company
If that was your first SQL statement, then congratulations!
The reason why I like using the Company table in the first SQL statement is that it's great prep for pretty much every other SQL statement that you'll run.
Why? Because you should pretty much always include CompanyID (1, 2, 3 in the previous screenshot) when running a query to restrict the data returned to a specific Acumatica Tenant.
Wait, Tenant? Then why isn't it called TenantID instead of CompanyID?
Well, first we need to make sure that we're clear about what a Tenant is in Acumatica.
You can see the Tenant in the drop down on the login screen (1st screenshot) or in the upper right-hand corner of the screen after you've logged into Acumatica (2nd screenshot).
Why isn't it TenantID in the database? The Tenant in Acumatica used to be called Company, but they renamed it to Tenant in Acumatica 2018 R1. I noted it here:
https://www.augforums.com/forums/everything-else/instance-vs-tenant-vs-company-vs-branch
Even though Acumatica now calls it Tenant on the front-end, they never changed CompanyID to TenantID in the database because that would have been a major pain.
So, when you see CompanyID in the database, just think Tenant.
That matters because we always need to filter the results from a query by CompanyID so we only get the data from the Tenant that we're interested in.
Back in that first screenshot, there are 3 Companies (Tenants) listed:
- 1 is the template Tenant. It contains template data like a list of Countries and States, Timezones, etc. So everyone's CompanyID of 1 has the same data.
- 2 is the first Tenant in your Acumatica database. In my Acumatica demo environment, SalesDemo is the first Tenant listed.
- 3 is the next Tenant. In my Acumatica demo environment, Another Tenant is the second Tenant listed.
So, if we want to see Customer data from the SalesDemo Tenant, then we need to filter on CompanyID=2 when querying the Customer table:
SELECT * FROM Customer WHERE CompanyID=2
Bottom line, make sure to filter on CompanyID when using AugSQL to query your Acumatica database.