Does an information schema exist before it is queried? - sql

In a SQL database, I can run a query to present information as it exists, and I can create new compilations of data that did not previously exist.
For instance, SELECT * FROM Table1 would return information that already existed, while a series of nested joins and WHERE statements could present data in ways that didn't exist before the query was run.
My question is whether the database's information schema -- assuming it's never been pulled up before -- falls into the first category or the second.

Information schema views query already existent system tables in database. You can control yourself as sys.tables etc which are called catalog views in Sql server.
Therefore using these views falls to second type of usage in your question. Using existent data in a different way.

Everything in INFORMATION_SCHEMA is just a view on the system tables. So the answer to your question is both that the data has always been there (because every object in the database has one or more rows in system tables somewhere representing it) and also that it's generated for your viewing pleasure upon querying (to present it in the form that INFORMATION_SCHEMA requires).
Note that even what we normally call "the system tables" (sys.tables and related) are also just views on the real, actual, physical system tables, which are not accessible to any user but only to the database engine itself -- viewing those directly requires a direct administrator connection and tweaking some flags, and is typically not something done by anyone other than SQL Server developers.
As to what this implies in a FOIA context is probably best answered in a legal setting, not an information-theoretical one.

Related

Custom Name for `information_schema` database

Is there a way to modify the SQL server to give the virtual information_schema database a different name by default?
Or is information_schema a standard so that software knows where to look and query for information?
I'm using 10.5.15-MariaDB - MariaDB Server
I'd like to rename it to .information_schema so that the database doesn't show up in the middle of the databases list on my CMS.
I don't have control over hiding/displaying databases by name.
information_schema cannot be modified or deleted.
If I were you, I would avoid any attempt to modify the default databases.
Here is what I found searching similar questions:
INFORMATION_SCHEMA is a database within each MySQL instance, the place
that stores information about all the other databases that the MySQL
server maintains. The INFORMATION_SCHEMA database contains several
read-only tables. They are actually views, not base tables, so there
are no files associated with them, and you cannot set triggers on
them. Also, there is no database directory with that name.
*(source)

Auto-Match Fields to Columns SQL LOADER

I'm trying to load some data from csv to Oracle 11g database tables through sqlldr
So I was I thinking if there's a way to carry those data matching the columns described on the ctl file with the table columns by the name. Just like an auto-match, with no sequential order or filler command
Anyone knows a thing about that? I've been searching in documentation and forums but haven't found a thing
Thank you, guys
Alas you're on 11g. What you're looking for is a new feature in 12c SQL Loader Express Mode. This allows us to load a comma-delimited file to a table without defining a Loader control file; instead Oracle uses the data dictionary ALL_TAB_COLUMNS to figure out the mapping.
Obviously there are certain limitations. Perhaps the biggest one is that external tables are the underlying mechanism so it requires the same privileges , including privileges on Directory objects. I think this reduces the helpfulness of the feature, because many people need to use SQL Loader precisely because their DBAs or sysadmins won't grant them the privileges necessary for external tables.

SSIS - Check OLE DB source schema

I have a ETL project that I need to load data from some 50K Access .MDB databases in a folder to sql server. Problem with those 50K databases files is that they have different schemas and I need the ETL process to be able to identify the differences and respond correctly.
For example, in some of the .MDB files there are table A, B and C. However in some other tables there are only table A and B (Same table A and B as compared to the other tables, just table C is missing). I need to put a check on each OLE DB source to see what tables are there to achieve logic like IF table A exists, load table A, otherwise, bypass the load.
I've done my googling and searched SO but all the error handling or check methods I could find are for the execute SQL task or data conversion task. So if anyone could shed some light on solution to my above case, I would be deeply appreciated.
Thanks.
In a nutshell - SSIS assumes that metadata does not change.
However, with some tricks, this restriction can be reduced; below is the list of suggested tricks:
Test for existence of specific table (see example here How to use SQL to query the metadata in Microsoft Office Access? Like SQL Server's sys.tables, sys.columns etc) and based on the result - do conditional execution of the following tasks.
All SQL requests to MS Access tables should have DelayValidation property set to True. Reason - postpone SQL command validation from package start to specific task execution. Some tasks (for missing tables) will not be executed; thus, it will not be validated and will not fire validation error.

Change schemas' structure in a PostgreSQL database

I have a Postgres database with some schemas (all have the same structure), I want to know if there is the possibility to change the structure (Table names, new columns etc) for all the schemas in the same database. Is it possible or what's the purpose of the schemas in a database?
Thanks.
I'm going to focus on the second half of your question, because I think it'll answer the first half (and I'm not sure I understand the first half).
what's the purpose of the schemas in a database?
This confused me when I first switched from MySQL to PostgreSQL. A Postgres schema is essentially the same as a MySQL database. In fact, according to the MySQL Reference Manual:
In MySQL, physically, a schema is synonymous with a database.
That begs the question of what is a PostgreSQL database, then? From the PostgreSQL Documentation:
More accurately, a database is a collection of schemas and the schemas contain the tables, functions, etc. So the full hierarchy is: server, database, schema, table (or some other kind of object, such as a function).
So a PostgreSQL database is essentially a collection of schemas? Seems kind of pointless, why do we need that step in the hierarchy? Let's take a look at the docs for a PostgreSQL schema:
A PostgreSQL database cluster contains one or more named databases. Users and groups of users are shared across the entire cluster, but no other data is shared across databases. Any given client connection to the server can access only the data in a single database, the one specified in the connection request.
A database contains one or more named schemas, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database he is connected to, if he has privileges to do so.
So, in PostgreSQL, a schema contains tables, functions, etc. And a database manages user/group connectivity and access/roles to specific clusters of schemas. Typically, I work under one database and have information broken into schemas to segment information.

Few questions from a Java programmer regarding porting preexisting database which is stored in .txt file to mySQL?

I've been writing a Library management Java app lately, and, up until now, the main Library database is stored in a .txt file which was later converted to ArrayList in Java for creating and editing the database and saving the alterations back to the .txt file again. A very primitive method indeed. Hence, having heard on SQL later on, I'm considering to port my preexisting .txt database to mySQL. Since I've absolutely no idea how SQL and specifically mySQL works, except for the fact that it can interact with Java code. Can you suggest me any books/websites to visit/buy? Will the book Head First with SQL ever help? especially when using Java code to interact with the SQL database? It should be mentioned that I'm already comfortable with using 3rd Party APIs.
View from 30,000 feet:
First, you'll need to figure out how to represent the text file data using the appropriate SQL tables and fields. Here is a good overview of the different SQL data types. If your data represents a single Library record, then you'll only need to create 1 table. This is definitely the simplest way to do it, as conversion will be able to work line-by-line. If the records contain a LOT of data duplication, the most appropriate approach is to create multiple tables so that your database doesn't duplicate data. You would then link these tables together using IDs.
When you've decided how to split up the data, you create a MySQL database, and within that database, you create the tables (a database is just something that holds multiple tables). Connecting to your MySQL server with the console and creating a database and tables is described in this MySQL tutorial.
Once you've got the database created, you'll need to write the code to access the database. The link from OMG Ponies shows how to use JDBC in the simplest way to connect to your database. You then use that connection to create Statement object, execute a query to insert, update, select or delete data. If you're selecting data, you get a ResultSet back and can view the data. Here's a tutorial for using JDBC to select and use data from a ResultSet.
Your first code should probably be a Java utility that reads the text file and inserts all the data into the database. Once you have the data in place, you'll be able to update the main program to read from the database instead of the file.
Know that the connection between a program and a SQL database is through a 'connection program'. You write an instruction in an SQL statement, say
Select * from Customer order by name;
and then set up to retrieve data one record at a time. Or in the other direction, you write
Insert into Customer (name, addr, ...) values (x, y, ...);
and either replace x, y, ... with actual values or bind them to the connection according to the interface.
With this understanding you should be able to read pretty much any book or JDBC API description and get started.