When Creating a DSN Less SQL Connection in Ms Access, How do I specify the Schema? - sql

I've done DSN Less 2 different ways, but neither seem to have a way to specify a schema.
I tried specifying to schema like [schema]. but it doesn't work.
Any idea how to get it to link up?

You don't specify the schema in the connection string, but specify that schema in the table name (or view).
So, the default schema is "dbo".
So for table customers and schema "dbo", you use
dbo.Customers.
If the schema is sales, or other? then you go:
sales.Customers.
So the connection to the database is un-changed.
You don't have to (or can) specify the schema in the conneciton - you specifty it in the table name.
Of course the local table name can be ANY table name you want - and you are free to include or not the prefix like this
dbo_Customers
Sales_Contacts
But, you can could use
Customers
Contacts
In fact, in most cases, if you doing a migration from a standard Access data file back end to SQL server?
Then you of course will keep the client side (linked) table name as to what it was before, and the linked table name does not have any special meaning in regards to the schema used.
So only the table prefix (dbo.) is how you select/change/use a database schema, and this ONLY applies to the server side name you use when creating a table link. As noted the client side linked table can be any name you want, and it can "only" include the schema if YOU decide to adopt some naming convention.
So, you specify the schema by prefixing the server side table name when re-linking, or creating a table link.

Related

What is the # sign in SQL used for other than parameters?

For a query which looks something like
select * from cus_query.ca_activity_vw#drifter
I imagine cus_query is the schema and the view's name is ca_activity_vw. But what is drifter ?
I quote the Oracle documentation:
If the identifier names an object on a remote database, you must reference it with its remote name. The syntax is:
simple_identifier_name#link_to_remote_database
If the identifier is declared in a PL/SQL unit on a remote database, you must reference it with its qualified remote name. The syntax is:
unit_name.simple_identifier_name#link_to_remote_database
From this page : http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/fundamentals.htm#LNPLS99945
drifter is a so-called database link - it allows to transparently query tables that reside on a different database (usually Oracle, but possibly some other RDBMS, e.g. via Database gateway).
To see the definition for the database link, you can use this query (this requires DBA privileges):
select * from dba_db_links

Naming conventions in pgAdmin3

I am creating tables in the GUI of postgreSQL, PgAdmin3. There is an element that seems to be specious in the naming of the tables. The following is my fragmented comprehension of postgreSQL (I could be wrong if I am, please rectify). I am inserting tables in the database using the ETL tool Talend.
When there is only one schema in the database: No reference to the schema is mandatory
select * from tablename
When there is more than one schema in the database: Reference to the schema is mandatory and the reference to the schema is required in quotes
select * from "schema".tablename
There is something new I drifted upon yesterday and I do not know what might be causing pgAdmin to do this:
select * from "schema"."tablename"
I am not oblivious of the part that referencing to the specific schema is mandatory when there is more than one schema present in the same database and in quotes but why does one need to have the table name in quotes as well.

How can I create a schema alias in DB2 on System z?

Part of a reporting toolkit we use for our development is configured to always use the same schema (say XYZZY).
However, certain customers have stored their data in a different schema PLUGH. Is there any way within DB2/z to alias the entire schema XYZZY to refer to the objects in schema PLUGH?
The reporting toolkit runs on top of ODBC using the DB2 Connect Enterprise Edition or Personal Edition 9.1 drivers.
I know I can set up individual aliases for tables and views but we have many hundreds of these database objects and it will be a serious pain to do the lot. It would be far easier to simply have DB2 auto-magically translate the whole schema.
Keep in mind we're not looking for being able to run with multiple schemas, we just want a way to redirect all requests for database objects to a single, differently named, schema.
Of course, if there's a way to get multiple schemas on a per-connection basis, that would be good as well. But I'm not helpful.
I am guessing that by DB/2 schema you mean the qualifying name in some two part object name. For
example, if a two
part table name is: PLUGH.SOME_TABLE_NAME. You want to do define XYZZY as an
alias name for PLUGH so the reporting program can refer to the table as XYZZY.SOME_TABLE_NAME.
I don't know how to directly do that (schema names don't take on aliases as far as I am aware).
The objection you have to defining individual alias names
using something like:
CREATE ALIAS XYZZY.SOME_TABLE_NAME FOR PLUGH.SOME_TABLE_NAME
is that there are hundreds of them to do making it a real pain. Have you thought about
using a SELECT against the DB/2 catalogue to generate CREATE ALIAS statements for
each of the objects you need to refer to? Something like:
SELECT 'CREATE ALIAS XYZZY.' || NAME || ' FOR PLUGH.' || NAME
FROM SYSIBM.SYSTABLES
WHERE CREATOR = 'PLUGH'
Capture the output into a file then execute it. Might be hundreds of commands,
but at least you didn't have to write them.

Oracle schema table name restrictions

I am looking into using JBoss 5.1.0GA on Oracle, and have seen this, warning that I should explicitly state the name of the schema into which the TIMERS table should be created, as Oracle doesn't permit the same table name to be used twice, even across schemas.
After reading this, I saw this question on StackOverflow, and would like some clarification about the hierarchy of objects in Oracle.
Suppose we have a single Oracle database server. Within this, we create two Databases - D1 and D2. Inside each database, we create two schemas - S1 and S2. Inside each schema on each database, we create a single table - T1 through to T4:
+-D1
| +---S1
| | +---T1
| +---S2
| +---T2
+-D2
+---S1
| +---T3
+---S2
+---T4
Am I correct in thinking that if I then add another table called T1 inside D1/S2, it will not work because the table names must be unique within the schemas, and T1 already exists in D1/S1, but if I add T1 to either D2/S1 or D2/S2 it will be fine because the two tables named T1 are in different databases?
I have a nasty feeling that my understanding of Oracle schemas is flawed (it is not a database I have used much before) so I'm sorry if I'm asking stupid questions.
Thanks in advance
Rich
the database hierarchical level doesn't exist in Oracle: an instance (set of processes) can only have one database (set of files) mounted at most. Inside a database you will find schemas which are also the same as users in Oracle.
Each schema has an independent namespace, e.g. schemas S1 and S2 can both have a table named T1 in the same database. You would specifically access these tables by using their owner as a prefix: S1.T1 and S2.T1.
Some objects don't have an owner (or their owner is PUBLIC) : Public synonyms and directories for example. The name of these objects will have to be unique in a database obviously. Use public synonyms wisely (=sparingly in my opinion) to avoid name collisions.
As far as Oracle goes, you can have the same table name in two different schemas. There may be something specific to the JBoss usage that you were reading about, but it is not an Oracle limitation.

Should the schema always be explicitly defined in the SQL statement?

Earlier I had asked the question:
Where (or how) should I define the schema in a select statement when using PostgreSQL?
The answer I accepted was to modify the search_path for the connecting user so that the schema need not be specified in the SQL. However, now I wonder if I should always specify the schema in SQL rather than allow the schema to be automatically inferred by the search path. This seems like it would be a safer approach and would be more portable to other databases.
This question is different than the previous one in that I want to know what the best practices are for defining the schema in SQL, rather than how it can be done.
Should the schema always be explicitly defined in the SQL statement?
** Note: I would not hard code the schema name but would allow it to be configurable through the Web.config file so that the schema could change from one installation to another. **
It's a bad practice to hardcode schema into SQL statements.
You should keep it in the application settings and issue SET search_path after connecting to the database.
If your application is used by multiple users with their own schemas, your life will be much easier if you don't hardcode schema name into SQL.
In other words,
string query = "SELECT * FROM " + ConfigurationManager.AppSettings.Get("schema") + ".table";
is a bad way;
SQLCommand("SET search_path = " + ConfigurationManager.AppSettings.Get("schema"), connection).ExecuteNonQuery();
string query = "SELECT * FROM table";
is a good way.
Let's see - in the DB of the app I maintain there are around a dozen schemas. What would be the order if I put them in "search_path"? And would I put in the schema names (not the tables name and not the fully-qualified table names) in the configuration?
As you have guessed by now I do not use "search_path". But maybe you could store the fully-qualified table names in the configuration in case you ever change you mind about the names of the schemas or the tables themselves.