Metabase is not showing synonyms - ssms

I want to define the relationship between a table I am joining, and the table I am joining it too.
The table I am joining on is a synonym of another database's table. I am doing it this way because the other database is a data warehouse of some sort, while the database that its the synonym for is more detailed data that I can access with id's and such off of the synonym.
However, in metabase, the synonym just doesn't show up. I can query off of them but I cannot configure them in the admin menu.
I am current trying it like so:
FROM dwBdgtAdmnstrtn AS relation
LEFT JOIN rdLctn ON rdLctn.id = relation.lctn
LEFT JOIN crmRltnGrp ON crmRltnGrp.id = relation.rltnGrp
relation is the synonym I am joining on to, and location and relationgroup are the 2 tables I want to define relationship to the synonym with so that I can use linked filters.
The query is functioning correctly, but without a relationship closely defined the linked filters don't work.

Related

Can I safely drop my table from schema 1?

oracle
In schema A I created a table called "apples" with data.
In Schema B I created a copy of table "apples" from schema 1 using
create table apples as select * from schemaA.apples
My question is, now that I have schema B up and running. Can I drop/delete my schemaA.apples? There is no direct link between the tables correct?
Or if I drop schemaA.apples will schemaB.apples get runied?
There is no direct link between the tables correct?
Correct. You have two different tables, that are not related. You just copied data from one table to another at a given point in time.
Or if I drop schemaA.apples will schemaB.apples get runied?
No, there is no risk that it will impact the other table. Again, data was copied, and tables are independent.
Side note: the create table ... as select ... syntax (aka CTAS) just copies the data and the structure, but not the related objects like primary keys, constraints, indexes, sequences. You might want to check these objects, and recreate them too to the new schema.

Inheritance MS SQL on SQL Server

I have this diagram:
Where both Professional and Patient inherit from the table user.
The user id id a PK.
Professional.id and Patient.id are primary keys of their tables.
They're also FK that reference user.id.
The question here is why when I do select * from Professional I don't get the inerited column from the table User?.
I know I can join them but I thought the concept of inheritance was supposed to share the fiels from the table User in this case to the tables Professional and Patient.
To answer your question - SQL Server is not an OODBMS. Though you logically have defined a type of inheritance, the engine does not provide any direct support for including the inherited attributes in the child "class". The query "select * from table" will only include columns from the specified table. You the developer must write your queries to select the tables and columns your statement needs.

FIND all tables I need to join to get relationship between two tables

I'm using SQL Server 2012. I want to join two tables without columns that I can join them, how can I find all the tables to reach to this two tables?
For example: I need to join the Table A to table D and to do that I need to connect A to B and then to C and at the end to D.
My question is: can I find the tables B and C among thousands of tables in the database without searching table by table?
Thanks a lot,
Ohad
Assuming that:
You want to automate this process
You have FOREIGN KEY constraints that you can rely on
You should proceed as follows:
Query sys.foreign_keys and create a directed graph structure that will contain the links between tables.
Then implement a graph search algorithm that will start from table A and try to find a path to table D and from D to A.
Once you have found the path, it will be easy to construct dynamic SQL containing the join of all tables on the path. You will need to query sys.foreign_key_columns as well to be able to construct the ON clauses of the JOIN's.
Let me know if you need help with more detail.
There's a couple of things you can do to help your cause, but for the most part, there's no direct way and you would need to know how your database is structured and the purposes of the tables. Furthermore, based on the database's design, it might be very difficult for you to intuitively find your answer and you might need just need to get guidance from someone who is knowledgeable with the database design. Regardless:
Fields in your tables A & D:
you can look at primary fields or unique fields in the tables to determine what other tables may link to those table. Usually they are named in a way that match those other tables and you can tell what table they're coming from.
Information_Schema Views
You can use information_schema.tables and information_schema.column views to easily search for names of tables and columns across the entire database and narrow your search to less tables.

Refer to table by id

Is there a way to reference a table by id. Essentially, the table contains rows which pertain to one of many tables.
e.g. I need to reference tables A or B or C in table D's rows so that I know which table to join on.
I assume that if there is no shorthand way to reference a table externally then the only option is to store the table's name.
There is a "shorthand reference" for a table: the object identifier - the OID of the catalog table pg_class. Simple way to get it:
SELECT 'schema_name.tbl_name'::regclass
However, do not persist this in your user tables. OIDs of system tables are not stable across dump / restore cycles.
Also, plain SQL statements do not allow to parameterize table names. So you'll have to jump through hoops to use your idea in queries. Either dynamic SQL or multiple LEFT JOINs with CASE statements ... potentially expensive.

SQL Reporting Service - Data Model

I create a data model that would replace two cut down tables. With these two table I placed a Many to One relationships.
When I create reports that just uses a single table (This is the Destination table, within Data source views relationship) its missing records that should be displayed. The records that do not display are records that do no have a linked record in the other table.
Help
You probably need to create a query or a view that includes an outer join. Search your docs for OUTER JOIN. That should take you where you need to be. Topics should include LEFT, RIGHT, and FULL outer joins.