How do I get SalesForce Table Names from SalesForce data - salesforce

How to get all table names in salesforce data using query. for example, In postgreSQL If i give SELECT table_name FROM information_schema.tables , it will give all table names from information_schema. Same way how can i get all table names from salesforce data?.

You can't do this with a query, but you can use the describeGlobal call (via SOAP or REST), or the Schema object in apex to obtain schema information include table & field names, types, etc.

Related

Is there a way to figure out the tables a snowflake query is accessing?

I looked up the SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY table but the information it provides is the database name. Is there a way in snowflake to get the table names a query is accessing ? I am not looking for a solution which involves parsing the query string, as that is really complicated.
To see what tables an historical query accessed, you can go to the History tab, click on the query ID for the query, and then click on the profile. For queries that you are about to run, you can see what table(s) it will access by typing "explain" before the query. That will produce a metadata result set with a list of tables the query will read from in addition to other information.
Edit: If the explain produces a very long result set and you want to filter it down to just the affected tables, you can do something like this:
-- Generate the explain metadata reult set
explain select * from MY_VIEW;
-- Filter to just affected tables
select distinct "objects" as TABLE_NAME
from table(result_scan(last_query_id()))
where "operation" ilike '%table%' and "objects" is not null;

Automatically produce aliases for all columns in SELECT statement

I'm using Microsoft Query to pull data from MS SQL Server to Excel. Many of my tables have the same column names, for example:
[task].[active]
[user].[active]
[task].[name]
[user].[name]
When I pivot in Excel, only the column names are shown. A pivot filter might have multiple fields called "active" which is very confusing.
I'd like to alias every column with the table name it's from, so that in the filter it would say "task_active" and "user_active". My Excel SELECT statement would be:
SELECT active AS task_active, name AS task_name FROM task...
Is there a quick way to prepend the table name to an alias using a formatting tool? I have Apex SQL Refactor, and Notepad++ but I haven't found a way to do this without having to manually type all of the column names again.
If you populate resultset to datatable then datatable to excel then it will automatically change duplicate column name to col1,col2 etc.
This is not your requirement.you want it to be specific.
Method 1 . Create temp table with desire column name
Insert the result in #temp table
Return #temp table result set
Method 2 : Use dynamic query.
Wht your real query look like ?

which view get all information about all data dictionary views?

I need data dictionary view that gets all info about all data dictionary view details in oracle
select * from user_dba;
desc dba_directiories;
It is called dictionary.
Looks like this:
SQL> desc dictionary
Name Null? Type
----------------------------------------- -------- ----------------------------
TABLE_NAME VARCHAR2(30)
COMMENTS VARCHAR2(4000)
You can query it like this (for example, searching for ones that talk about "constraints"):
SQL> select * From dictionary where lower(comments) like '%constraint%';
TABLE_NAME COMMENTS
------------------------- --------------------------------------------------
ALL_CONSTRAINTS Constraint definitions on accessible tables
ALL_CONS_COLUMNS Information about accessible columns in constraint
definitions
USER_CONSTRAINTS Constraint definitions on user's own tables
USER_CONS_COLUMNS Information about accessible columns in constraint
definitions
SQL>
You can use following query on system-supplied DICTIONARY view which contains the names and abbreviated descriptions of all data dictionary views.
SELECT * FROM DICTIONARY ORDER BY 1
It has mainly divided into 3 sets. So the views with
- Prefix DBA_ show all relevant information in the entire database. DBA_ views are intended only for administrators.
- Prefix ALL_ refer to the user's overall perspective of the database. These views return information about schema objects to which the user has access through public or explicit grants of privileges and roles, in addition to schema objects that the user owns.
- Prefix USER_ views most likely to be of interest to typical database users are those with the prefix USER_.

Stored procedure to update a table based on data from table parameter

I want to begin by stating I'm an SQL noob, so I'd appreciate any suggestions or comments on my workflow and/or mindset when trying to solve this issue.
What I'm doing is gathering usage statistics about several applications, in several categories (not all categories necessarily apply to all applications), storing them in a database.
I've set up a few tables to do that, and then one table to link everything together that's structured like so (from now on: Dtable):
(column name - details)
UserID - foreign key to another table which stores users data
ApplicationID - foreign key to another table which stores applications data
CategoryID - foreign key to another table which holds a list of different categories
Value - the actual data
Each application gathers the data, then submits it to the database using a stored procedure. As the amount of data can be different based on actual usage (not always sending every category) and for each application, I was thinking of sending the data as a DataTable with a list of CategoryID and Value so I won't have to call a procedure for every individual category (Ptable).
I need to update each record in Dtable to the correct value in Ptable according to CategoryID, but also filtered by UserID and ApplicationID. UserID and ApplicationID will be given as two other parameters to the Stored Procedure. Ptable only contains a list of CategoryID / Value records.
Now, I read about Cursors (for each record in the table parameter set the relevant data in the database table), but the consensus seems to be "Avoid at all costs".
How would I go about updating the table, then, based on the varying records in Ptable?
P.S.
The tables are structured like so to keep agility and scalability in adding more categories/applications in the future. If there's a better way to do it I'll be happy to know.
I believe the update statement would look something like this, where #ApplicationID and #UserID are the stored proc's other parameters:
update Dtable
set Dtable.Value = p.Value
from Ptable p
where Dtable.UserID = #UserID
and Dtable.ApplicationID = #ApplicationID
and Dtable.CategoryID = p.CategoryID;

Copying data from old database to new one with a new structure

I had an old database with a single table containing customer orders and customer details. I went on to create a new database model using seperate tables for customers and details. I managed to migrate the customer details to the new database, but was unable to migrate the the cusomer orders. We thought that this would be ok, and that we would just build the order record from now on ignoring all previous orders in the old database. This was a while ago, and I cannot remember the exact reason why I was unable to import the customer orders. However, now we have discovered that we will need the old orders in the new database. Is there an easy way to do this using Microsoft Access?
This is the reason why:
Split a table in access into two linked tables
Depending on how complex your schema is, a simple approach would be schema-mapping by a INSERT INTO SELECT query.
For example if your old database had a table:
Orders
------
OrdID
CustID
ProductName
Price
oDay
oMonth
oYear
And your new database had fields with different names, extra fields, etc:
OrderDetails
------
Order_ID
Customer_ID
Product
Price
DeliveryAddress
OrderDate
All you would need to do was to create an insert query to append the old records to the new table. In defining the query, you can specify the source and destination field names, and you can even perform functions / expressions on the data. You can even query on the other table directly, without linking or importing it into your new database:
INSERT INTO OrderDetails (Order_ID,Customer_ID,Product,Price,OrderDate)
SELECT OrdID,CustID,ProductName,Price,DateSerial(oYear,oMonth,oDay) AS oDate
FROM Orders IN 'C:\oldDatabasePath.mdb';
If you have to do additional transformations to the data, such as run expressions on column values, I would recommend testing out the SELECT part of the query before adding the INSERT line.

Resources