Explicitly refer to public DBLink when schema owns a private one of same name? - sql

I'm working a migration project requiring an import of several Oracle database schema onto an existing database. This requirement has brought about an interesting conflict where I now have two dblinks with the same name:
One is a private dblink which uses account A to access the Foobar database
The other is a public dblink to the same Foobar database which uses account B for its access
Global Names is set to true so I cannot change the names of these dblinks.
I've already figured out through trial and error that when signed into schema that owns the private dblink that the following:
SELECT *
FROM table#foobar;
will refer to the private dblink and not the public one. But for situations where I require the account B privileges, I cannot figure out how to explicitly refer to the public dblink.
Does anyone know of syntax I can use to refer to the public #foobar?

From Oracle documentation.
Oracle first searches for a private database link in your own schema with the same name as the database link in the statement. Then, if necessary, it searches for a public database link with the same name.
I don't think this can be changed in any way. Not that I know of or found in documentation. You could create public synonym but that will work only if you need to access with B specific objects. Synonym can't be created for whole database link.
Wouldn't it be easier to turn global names to False on session level and create new link to B with otherwise invalid link name. If you change global names on session level only that session will be allowed to use new link.

Related

Unable to select all rows of information_schema.triggers

I have two kinds of users in my Postgres database. One has access to everything in the database and has admin access. The other kind has SELECT access on public schema and USAGE access on information_schema.
When I run the following query, the second kind of user sees only a subset of all results which the first kind of user can see.
SELECT action_statement, event_object_table
FROM information_schema.triggers;
I am not able to understand what could be happening here. Triggers on the table from same public schema are present, but miraculously some triggers are missing for other tables in the same public schema.

PostgreSQL - correct db privileges for an API user account

I have a REST service which will be connecting to a PostgreSQL database. The application will only be executing INSERT/UPDATE/DELETE operations. I want to make sure I give the API account the correct permissions to only execute these type of commands and not DROP and other dangerous operations. What are the best practices for this type of accounts and can you give me some SQL examples or instructions how to do this in pgAdmin 4.
When you want to limit access it is often wise to start with clearing out all permissions public might have. Besides being the name of the default schema public is also a special role that includes all roles so if public is allowed to do something everybody is allowed to do it.
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM public;
REVOKE ALL ON SCHEMA public FROM public;
Then set the authorizations for your user(s).
GRANT USAGE ON SCHEMA public TO api_user;
GRANT SELECT INSERT UPDATE DELETE ON ALL TABLES IN SCHEMA public TO api_user;
If you have other schema's besides public repeat for those.

object name already exists: PUBLIC in HSQLDB

I have an HSQLDB database (script/log) that I want to read into an In-Memory database. This script has near its top:
CREATE SCHEMA PUBLIC AUTHORIZATION DBA;
which leads to an error. So I tried executing that manually and I don't understand the result. Here's what I did:
Why do I get object name already exists: PUBLIC / Error Code: -5504 / State: 42504?
Did I not drop the schema correctly or why am I unable to create it?
The PUBLIC schema exists in all new databases. When you drop the PUBLIC schema, an empty version gets recreated automatically. Therefore, you do not need to create the PUBLIC schema.

SQL Server 2008 R2 how to change dbo.tablename to Domain\UserName.T_TableName

Question: when I create a table (T_TableName) using SQL Server Management-Studio, it always creates the table as
dbo.T_TableName
instead of
Domain\UserName.T_TableName
What's wrong ?
It is also known as Database Owner.
Database Owner is the default schema in SQL Server.
Database Owner offers simplified ways to group objects.
dbo is a special schema - it is is present in every database and, typically, it is the default schema for users. It stands for "database owner". If you do not explicitly specify a schema when you refer to an object,
SQL Server will go to the default schema. This is perhaps why you sometimes see this schema and sometimes not. NOTE that it is typically considered bad practice not to explicitly state the schema when referring to an object, so whereas you are keen to not qualify all objects with the schema name, if I got hold of your code I would add the schema name in.
Answer is Reffered From one of my Favourite author :
See
These are some link Please refer this also.
Click Here

can we create synonym with the same name in same schema

I'm preparing for SQL Expert certification, and I found one question and It said,which is the correct option. And, out of four, one option said A table and a synonym can have the same name in the same schema.
And, per my knowledge, in oracle anything we create that treated as an object, which means when we say create synonym, which means we are creating new object. And create same object in same schema not allowed in Oracle or any database AFAIK.
Even Burleson says
You can have a public and private synonym of the same name. In fact,
you can have a public and private synonym called EMP in the SCOTT
schema and have a table called EMP in the same schema
So, I tried.
create synonym emp for scott.emp
It shows some error object already exist
Then I tried
create public synonym emp for scott.emp.
And, got same error. So, anyone please share some knowledge on Synonyms. Can we create synonyms with same name in same schema ?
You can have:
Table and Public Synonym with the same name
Public Synonym and Private Synonym with the same name
But can not have:
Table and Private Synonym with the same name inside the same schema
The first thing to note is that Public Synonyms are non-schema objects, while Private Synonyms and Tables are. Another is that the uniqueness of database objects' names are defined by the namespace. As it is stated in SQL Expert Study Guide:
USER, ROLE, and PUBLIC SYNONYM objects are in their own collective namespace.
TABLE, VIEW, SEQUENCE, PRIVATE SYNONYM, and user-defined TYPE objects have their own unique namespace within a given schema.
INDEX objects have their own namespace within a given schema.
CONSTRAINT objects have their own namespace within a given schema.
So, as long as objects do not share the same namespace you can give them the same names.
Hope this helps.
Public synonyms are non-schema objects, when private synonyms as tables are schema objects.
USER, ROLE and PUBLIC SYNONYM are in their own collective namespace.
TABLE, VIEW, SEQUENCE, PRIVATE SYNONYM have their own unique namespace.
An INDEX has their own unique namespace.
A CONSTRAINT object has their own unique namespace within a given schema
While the objects don't share the same namespace, you can give them the same names.
Remember, that you can have:
a table and public synonym with the same name
a public synonym and a private synonym with same name
You cannot have:
a table and a private synonym with the same name inside the same schema.