In an effort to find some namespace-like structure in PostgreSQL that's nestable (so not schemas), I stumbled upon this page in the official documentation referencing a catalog to define namespaces in. Link to documentation page. It's not obvious to me what a system catalog is in PGSQL, but is this something I can interact with and create namespaces on my own? I'd love to have a nestable name-scoping tool.
Future thanks.
In an effort to find some namespace-like structure in PostgreSQL that's nestable (so not schemas),
pg_namespace reflects schemas created by CREATE SCHEMA, plus schemas created automatically like pg_toast, pg_temp_NN...which doesn't have any nesting.
There are no nestable namespaces in SQL.
It's not obvious to me what a system catalog is in PGSQL
This question has good answers that might help:
What's the difference between a catalog and a schema in a relational database?
Related
This might be a case of me over thinking the problem, but how should I document an HBase schema? In relational database land, it is common to use UML or similar diagramming techniques to document schemas. Those approaches don't seem to fit HBase very well. To me the simplest approach is to use a spreadsheet (or any other table) to document the columns and column families. Is there a better way to do this?
There's no common method at this point. You can do it in whatever way seems clearest to you. I've used entity diagrams (generally more trouble than they're worth), XML/JSON, and pseudo CREATE TABLE statements. A couple things that might help:
A presentation I did at HBaseCon 2012 about understanding HBase schema design, which proposes a few simple guidelines.
An simple open-source tool called scoot that takes in XML files and outputs JRuby scripts for creating said schema
If you're getting into advanced stuff like "entity nesting" (i.e. using variable columns at runtime) then you're kind of on your own as far as modeling goes, for now.
In SQL:2008, and also previous standards, the INFORMATION_SCHEMA is described as the standard meta-schema. In principle, meta-data could be unloaded into XML for further processing and reverse-engineering of schema meta data with XSLT and other XML tools.
Has this been done before?
Is there a somewhat complete XSD available, that describes the INFORMATION_SCHEMA?
N.B: I'm asking this because I would like to implement unloading of a database schema into a SQL standard INFORMATION_SCHEMA XML structure in jooq-meta, and then in a second process to load that schema again, to generate Java source code artefacts in jOOQ. For that, I would prefer not to roll my own XSD, but use a pre-existing as-close-to-the-standard-as-possible XSD
ANSI/ISO have not defined a particular way of representing a database schema using XML.
The latest standard is SQL:2011.
Here you can see the list of official standards. But, as you can see, they're not free:
35.060: Languages used in information technology
Look for ISO/IEC 9075-x in the list. As you can see there's still only the old INFORMATION SCHEMA.
So, your only option is to look for something widely used. Altova has its own way of doing this (a function named "Create XML Schema from DB Structure"). Look at this link:
How to Convert a Database to an XML Schema
This application has also options to create the database from the exported schema.
I think this is the closest to an standard that you can find (Altova is one of the leading XML software companies. If there was some kind of standard they should know it and use it).
Oxygen XML has also its own way of doing this, and it lloks like there is some kind of "IOS draft":
Extract XML Schema From a Database Structure
Is it a good idea to create a schema type to separate the table relationships. I guess when you are browsing the tables in SSMS you will see them group together by schema type. But is it worth the trouble? Anyone with experience with this in real world scenarios?
I've generally found that to be more of a hassle than any help it's provided. What do you do with tables that are relevant to multiple areas? What happens when a table seems to belong to one area but later migrates to another area of the application? Do you change its schema and refactor all of your code?
I have used multiple schemata to make delineations when there is a VERY clear boundary between objects, but usually not something like what you have in your diagram. One example is objects which are used just for DBA support. I might put those into their own schema if they aren't used by the actual application itself.
At my work everyone has sql snippets that they use to answer questions. Some are specific to a customer, while some are generic for a given database. I want to consolidate those queries into a library/repository that can be accessed by anyone on the team. The requirements would be:
Accessible
Searchable
Tagable (multiple tags allowed per sql)
Exportable (create a document containing all queries with certain tags)
I'm interested in what has been found to work in other team environments.
You could use a wiki.
You could get started with something as simple as Tiddly wiki.
A wiki is a great approach.
For database specific or project specific snippets it's also very useful to have links to where a similar construct occurs in the code. We use trac's wiki which gives nice integration with out SVN for this.
Rather than pasting SQL snippets, I would consider graduating to an ORM (Object-Relational Mapper) or some other library to make representing and manipulating the data easier. It provides a layer of encapsulation to guard against schema changes and a layer of abstraction so you can think of the data in terms of business logic (ie. a user) rather than a collection of tables (ie. a user table, a password table, an access table...).
In Perl this would be something like DBIx::Class.
Another approach you may want to look at is creating views in your database. 'select * from some_view' can hide quite a bit of SQL. You'll still want to use a wiki to document them, but if its a view you don't have to worry about people keeping outdated copies.
select sys.database_name,sys.sysevent,sys.login_user from dual;
what is sys in this query?
Can I see the other functions that are in sys?
What is the query for doing so?
In what situations is this sys useful?
Where will be the information about sys is stored in database?
sys is the system schema. It holds various tables and views that support the rdbms.
You might check out the oracle wiki article which talks about the various schemas and their meaning.
http://en.wikipedia.org/wiki/Oracle_database
In many database systems, including the major database products from Oracle, Microsoft and Sybase, groups of related database tables can be pulled together into a schema.
Some large systems (and, for that matter, some not so large systems) use this as a way to control access, or just as a way to keep things well organised.
For example, the tables supporting an online catalog (e.g. Amazon or Barnes & Nobel) might all be Marketing.*, the tables around order fulfillment Sales.* and those around Stock management Stock.*.
The sys schema that you've noticed is where system tables live - tables that you can query to find out details about the rest of the database - such as whether a column already exists.
I agree with Bevan. Here are some answers specific to your questions:
(I'll make the assumption you're talking about Oracle)
Can I see the other functions that are
in sys?
Yes, like any schema you can view the procedures, functions and packages in sys using a database development tool such as Toad, PLSQL Developer or Oracle SQL Developer. However my experience has shown that referring to Oracle documentation (freely available online) is a better way to learn about the available functionality than jumping straight to the source code.
What is the query for doing so?
I'd recommend the use of one of the development tools above. Failing that, try:
select * from user_objects where type in ('PACKAGE', 'PROCEDURE', 'FUNCTION');
Once you've found the functionality you're looking for use the DESCRIBE command in SQLPlus to determine the method signatures and data types.
In what situations is this sys useful?
SYS is most often often used as a super user for adminstrative tasks as it has more privileges than a common schema. SYS also contains a lot of the infrastructure on which Oracle depends - don't mess around with the objects that SYS owns.
Where will be the information about sys is stored in database?
Use the methods I have suggested above - but I recommend you read the online documentation rather than dive straight into the source.