Define Federated Object on DB2 - database

I'm currently learning the basics of DB2 in school.
Right now we are working on Federated Data Sources.
I've been trying to solve this one exercise, but I'm stuck:
In database DB001, table SH1.TB001 is to be included as a Federated Data Source.
The Federated Object should have the name NTAB (the nickname) and be defined in schema SH1.
I'm searching a solution on the IBM Knowledge Center, but I couldn't find anything.
I have to work essentially directly on my CentOS server, with the terminal. The only "external" programm I can use is DBeaver.
Since I have no experience with this, any type of help or advice is appreciated!

there is two way to access remote data in DB2:
1.create a nickname, and use it as local table:
Create NICNAME SCHMx.NICKNAMEx for <remote server>.<remote schema>.<remote table>
then you can use SCHMx.NICKNAMEx as a local table:
select count(*) from SCHMx.NICKNAMEx
2.Use Federated three-part names:
select count(*) from <remote server>.<remote schema>.<remote table>
you can find the documentation her: https://www.ibm.com/support/producthub/db2/docs/content/SSEPGG_11.5.0/com.ibm.data.fluidquery.doc/topics/iiyfq3pnintro.html

Related

Snowflake - Querying External Table from Tableau

I am trying to use the Snowflake connector in Tableau to query an external Snowflake table.
I cannot see the external table in the list of all tables on the left pane in Tableau (only regular Snowflake tables), so I have tried to pull from the external table using SQL.
Running this from the Snowflake site gets me the contents of the external table:
select * from EXTERNAL_TABLE_NAME;
Running the same from the "New Custom SQL" dialog in Tableau's Snowflake connector gets me this:
SQL compilation error: Object 'EXTERNAL_TABLE_NAME' does not exist or not authorized.
I also tried the following:
select from #DATABASE_NAME.SCHEMA_NAME.STAGE_NAME.EXTERNAL_TABLE_NAME
...which gets me: SQL compilation error: Object does not exist, or operation cannot be performed.
Any thoughts on what I can do to get this to work? I don't think it is a permissioning issue because I am using the same account to auth in Tableau as I am on the Snowflake website.
I'm guessing that I simply need to do a better job pointing to the location where the external table is, but I can't figure it out.
Thanks in advance for your help!
Looks like this is a deeper permissioning issue that I will have to resolve with our Snowflake admin. I was able to pull to Tableau from an external Snowflake table successfully using a different ROLE and DATABASE, so marking this resolved.

How to solve the sql execution error in snowsql client?

I am getting error while creating a table in snowsql client which says
003540 (42501): SQL execution error: Creating table on shared database 'SNOWFLAKE_SAMPLE_DATA' is not allowed.
can anyone help me out how to resolve this error?
Snowflake sessions have "context", such as current role, warehouse, database, and schema.
It appears your current session "context" has your database set to one of sample databases,
which was created from a "Share".
Databases created from a share are readonly, so you cannot create a table in them.
The good news is the fix is easy, you can either:
use a fully qualified table name (databaseName.schemaName.tableName) to create your table in a database/schema that you have proper access to.
USE DATABASE snowflake_sample_data;
USE SCHEMA tpch_sf1;
CREATE TABLE myDatabase.mySchema.myNewTableName AS SELECT * FROM lineitem;
change your session context to a database/schema you have access to create tables, and use the fully qualified table name of the tables you are reading from.
USE DATABASE myDatabase;
USE SCHEMA mySchema;
CREATE TABLE myNewTableName AS SELECT * FROM snowflake_sample_data.tpch_sf1.lineitem;
Relevant docs links:
https://docs.snowflake.com/en/sql-reference/sql/use.html
https://docs.snowflake.com/en/user-guide/data-sharing-intro.html#how-does-secure-data-sharing-work
https://docs.snowflake.com/en/sql-reference/name-resolution.html
https://docs.snowflake.com/en/user-guide/sample-data-using.html#querying-tables-and-views-in-the-sample-database

Equivalent of Oracles sys_context ('USERENV', 'Client_Identifier') in SQL Server

I have been looking for equivalent of Oracles sys_context ('USERENV', 'Client_Identifier') in SQL Server.
I have been actively looking but got no correct answer, the above function is used in Oracle to identify the front end application user and I want to identify those application users in SQL Server. So far everywhere everyone is giving answers and I've looked into them but they are giving answers about database level, like which user is logged in right now on database but I want to identify the front end application user and use its email or name to insert into a field
Check out SP_SET_SESSION_CONTEXT to set a value
https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-set-session-context-transact-sql?view=sql-server-ver15
and SESSION_CONTEXT to retrieve it

Azure - How to execute UDF from external data source in select statement

I have an external data source created in DB1 and its pointing to DB2 database in Azure.
I want to query a UDF defined in DB2 from DB1.
Following syntax works, from DB1:
EXEC sp_execute_remote
N'Ext_DB2',
N'SELECT Result'
But I want to use following syntax:
select C1, C2, < function_in_DB2 >
from t1
I tried searching web, this format is not mentioned anywhere, is it not supported? Any pointers will help.
Thanks !
Just per my experience, I think Azure SQL database doesn't support it. As we know, we can't do cross database query directly.
Since none document talk about this, I would suggest you ask Azure SQL support to get more support, ref: How to create an Azure support request.
Hope this helps.

DB Link from Oracle to MS Server

I am new to this forum and already searched for 45 minutes to find a solution for my problem. I hope you can help me.
A Gateway to a remote Microsoft SQL Database was installed on a Oracle Server (Oracle 12c). The tsnnames.ora file was appropiately set up.
For the connection, I created a database link (In the Oracle DB) as follows:
CREATE DATABASE LINK TEL CONNECT TO "fb_B2C" IDENTIFIED BY "passwort" USING 'dg1msql';
When I now execute the Select statement:
SELECT "name" FROM "sys"."databases"#TEL
it shows me the according databases. Among others, I can see the AB_Colors database.
Now, I want to select a view in the AB_Colors database.
Due to the fact I can connect to this database via Excel, I know that in the database AB_Colors, there are 10 Views(A,B,C,..). I would like to select the View C from the database AB_Colors via the DB LInk.
Owner of the View is b2b.
How do i need to formulate the select statement to do it?
I already tried different writings:
SELECT * FROM b2b.C#TEL;
SELECT * FROM "AB_colors"."b2b"."C"#TEL;
SELECT * FROM [AB_Colors].[b2b].[C]#TEL;
The common error message is: View/Table does not exist
I highly appreciate your help,
Fedja
This is the correct format
SELECT * FROM "b2b"."C"#TEL;
The issue maybe because the database you want to select from is not the one specified in the gateway for dg1msql. You can't add the database name to the query so you must specify it in the gateway connection.
This is defined in
$ORACLE_HOME/dg4msql/admin/initdg4msql.ora
where you should check HS_FDS_CONNECT_INFO

Resources