How to solve the sql execution error in snowsql client? - snowflake-cloud-data-platform

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

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.

SQL Server User-Defined Table Type / Crystal Reports Error

I was forwarded a Crystal Reports error message that said:
Failed to retrieve data from the database. ... Description: The EXECUTE permission was denied on the object 'xxxx_IDList', database 'DBName', schema 'dbo'.
There is an 'object?' named 'xxxx.IDList' under User-Defined Table Types - in the database.
I have never created or used a User-defined Table Type so I am just trying to figure out how to approach this error and how I might proceed with troubleshooting it.
I am hoping this is not an uncommon error.
Can anyone suggest an approach to solving this problem?
Thanks in advance!
In SQL server, any table that is not a system table is a user-defined table. So, anything in a typical non-system database that holds business data. The error message tells me that you have a database (dbname) on the server you are connecting to. In that database there is at least one schema (dbo, which is the default) and that the table xxxx_IDList lives in that schema.
Your app is trying to execute this table as if it was a function or stored procedure and you do not have permission to do that.
Do you have the source for the app that we can look at?

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

Getting data from another Database within procedure in DB2

I have two databases DB1 and DB2 and I want to call a stored procedure in DB1 and get data from DB2.
Create procedure diffdbtest()
LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE C1 CURSOR WITH RETURN FOR
SELECT * FROM Db2.myschema.tabletest;
OPEN C1
END#
I get Db2.myschema.tabletest is not defined.
Both DBs have the same user and password (if possible how can I use different users?)
Any idea what is wrong?
Running DB2 Express v10.5 Windows
Thanks.
The only way as far as I know is you have to use federation. You need to:
create server wrapper to DB #2
create nickname on table that is referring the table tabletest
create user mapping
etc.
Then, you can access that table via nickname.
Details on how to do this can be found in knowledge center: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.data.fluidquery.doc/topics/tlsdb201.html
Hope this helps.
Kevin See
Db2 Hybrid Cloud Security Dev Team

Access A table synonym created in a DB through a DB Link

Problem :-
Table is present in Database 1.
Synonym of the table is created in Database 2 using Db link created in Database2 which is pointing to Database 1.
Another DB Link created in Database 3 pointing to Database 2.
While accessing the Synonym of the table present in Database 2 its giving the error :-
ORA-00980 synonym translation is no longer valid
So i guess we cannot access a synonym present in a remote database and its object is present in another remote database.
Any suggestions on the above scenario. What would be the best solution for the mentioned problem.
It seems db-link from DB3 to DB1 may help.
See Ask Tom (notice, below DB3 <- DB2 <- DB1, procedure compiled on DB1):
CAUSE
This issue was reported in Bug 2829591 QUERYING FROM A PL/SQL
PROCEDURE IN 9I -> 8I-> 7.3.4, GETTING ORA-980. This bug was closed
as 'NOT A BUG' for the following reasons
PL/SQL cannot instruct middle database (DB2) to follow the database
link during the compilation phase. Therefore in order for this PL/SQL
block to compile and run, both database links dblink1 and dblink2
should be defined on the front end database - DB1. During runtime
database link dblink2 will be looked up in DB2 as expected.
SOLUTION
To implement the solution, please execute the following steps:
Create a database link dblink2 on DB1 pointing to DB3
...
Create and compile the PL/SQL block on DB1.

Resources