How can I confirm which RDBMS I'm using (in any form of SQL)? - sql

I'm writing instructions for people who are completely new to SQL and who are probably using an interface to talk to the database. The interface might be a SQL editor provided by their workplace, or it might be software (e.g. a BI reporting system) that allows them to write a query rather than use the gui. These are business people, not IT.
The first thing I want them to do is identify which RDBMS they have, so we can establish which type of SQL they need to learn. I.e. is it Oracle, Microsoft, MySQL, PostGre et al. I feel silly asking this: but is there an SQL command that works across all RDBMS to tell them this? The closest I've got is select version(), but this only gives the version number, not the RDBMS name. And anyway it isn't consistently implemented.

If the ANSI information schema is available:
SELECT * FROM information_schema.sql_implementation_info;
In particular the "DBMS NAME" and "DBMS VERSION" fields.

Usually, if they are using some sort of BI system, you can simply check the configuration of the software where the connection parameters are set

Related

If I'm using PostgreSQL, do I need a server too? Like AWS RDS?

In my CS program, I was told I should learn SQL for my databases.
If I'm using PostgreSQL, do I also need a SQL server to go along with it? Is PostgreSQL a language, a server, or both? Is there even a SQL language or is it only servers?
Background: I downloaded Postgres because hey, that has SQL in the name, it works and I'm under the impression it's a pretty good choice anyway. But I couldn't figure out through their website if it needs a companion server, so I went looking for one and found AWS RDS.
The impression I have is that Postgres is the language and AWS RDS is the server, and they serve different functions. But I'm not sure about any of that.
Seems you're learning too many new topics at the same time.
Ok. I'll try to answer.
SQL stands for 'Structured Query Language', and serves as a 'standard' for many vendors that in much ways respects its fundamentals. Oracle, MySQL (now owned by Oracle), MariaDB and PostreSQL are some vendors.
Main thing with SQL code I would recommend you to identify every time you look at it, is to understand if it belongs to DML or DDL. DML stands for 'Data Manipulation Language' and refers to SQL instructions which 'modifies' data. DDL stands for 'Data Declaration Language' which defines or 'alter' de structure on which data will be stored.
Another important concept is atomicity of data manipulation. You can confirm a change or roll it back before it is persisted. This thing corresponds to 'commit' changes or do a 'rollback'. It's some kind of advanced concept, but generally happens "automatically" with standard client configurations. Later, you would have to know about it while programming some system module which interacts with databases.
When you think of the SQL 'server', it refers to the software configured/installed which has the responsability of manage persistence of data within some kind of 'instance' of persistence, allocated in some system with data storage capabilities. AWS implements this service in the cloud, and RDS is the product which supports many kind of SQL flavors to choose (Oracle, Postgresql, etc.)
If you are comfortable with Docker, I recomend you learn the basics which would help you setup and destroy databases many times, which is useful to develop and test locally. Next command, let you start a Postgresql database configured with open port 5432. You can see the server log through docker and use some SQL client to get connected. When you press Ctrl+C everything will be deleted. Of course there are other ways to keep data persistent, but this command would be an easy starting point.
$ docker run --rm -p 5432:5432 --name some-postgres-container-name -e POSTGRES_PASSWORD=mysecretpassword postgres:13.3
Side note: it's better to get used to work with specific docker image versions always (not 'latest').
More details of it usage here: https://hub.docker.com/_/postgres/
if I'm using PostgreSQL, do I also need a SQL server to go along with
it? Is PostgreSQL a language, a server, or both? Is there even a SQL
language or is it only servers lol? I'm genuinely trying to figure
this out myself, but basically everything I read is beyond my scope of
competence and confuses me more. I'm learning the syntax of SQL well
enough, but I'm so confused about everything on the most fundamental
level.
By the way "SQL Server" is Microsoft's SQL flavor, just another one. Don't be confused with the concept of having some SQL server configured.
Yes, you can think of PostgreSQL as a language too, which shares most of its syntax and semantics with other SQL vendors. Yes, there is a 'basic' SQL language shared and compatible between all vendors; some share more aspects than others. In terms of Venn diagrams, you can think of many circles representing each one, Microsoft's SQL Server, Oracle SQL, PostgreSQL, MySQL, etc. sharing the very most of its elements, where each element is a SQL instruction.
When dealing with Databases in general, keep in mind that they helps to modelate situations of 'real world' scenarios or software systems. SQL allows to 'talk' to implementation of "Relational Databases" wich is one kind of database modeling, but there are others too. ER Diagrams helps to represent the 'structure' of a database in a conceptual manner. I like DBeaver because it has an integrated ER diagram generator wich helps to understand the structure of a given database instance.
I have used Postgres and it is an excellent product (and free).
I would install it standalone first. It does come with its own client tools, which you use to communicate with the database server, which runs independently as a service. However, you might be better off installing something like SqlWorkbench as a client tool (which I use). In the config you specify the machine Postgres is running on (which can be your local computer for testing purposes) and the port to connect on. Essentially, the client sends your instructions to Postgres server and the server returns the resultsets associated with your instructions. The client also formats the resultsets into a nice readable "spreadsheet" format with rows and columns.
First I'll try to answer the questions you asked. There is a SQL language, but in practice it is not strictly standardized. There are many offerings for databases and database servers. Many of these are discussed below.
Any database you pick will give you the chance to learn basics of SQL queries and this knowledge will serve you well even if you switch to a different database later.
Specifically, when it comes to PostgreSQL, it is a Relational Database Management System. It is a software that operates as a server. You can install it on your personal computer running Windows, Linux, or MacOS. You can also install in on a dedicated server computer where you'll get better performance and uptime. Further, there are many companies that offer PostgreSQL hosting including Amazon RDS and Google Cloud but they're not free.
For a CS student, PostreSQL installed on your personal computer might be a reasonable choice. But you have lots of options. Read on....
For a CS program, your choice of database will depend on:
what degree of portability you need
how much data you have
how many users will connect to database
what kinds of jobs you might pursue after graduation
Portability
If you think you want to ship your database with your application, then your best bet is probably SQLite. By some accounts it can handle several million rows worth of data and still be performant. However, it's not great if you need for multiple users to connect to the same database. Your data can get corrupted in many multi-user scenarios.
How Much Data and Users
For large data and large users, you'll want to consider the client/server heavy hitters:
PostgreSQL
MySQL/MariaDB
Oracle
SQL Server
These databases will support large quantities of data any many simultaneous connections. But if you want to distribute the database with your application, it's not a good idea. Or if you want to demonstrate your app, you need to ensure that a connection to a server will be available. All of these databases come with a free version, but the last two will have the most restrictions.
After Graduation
Now you're looking to the future and possibly what kind of skills you want to put on your resume. If you think you'll end up in a corporate environment that is already well established, they will likely already have a preferred database and it could be any of the ones listed here (SQLite or the "heavy hitters"). If you want to position yourself as developing apps with low overhead cost, you'll gravitate towards SQLite/PostgreSQL/MySQL. If you think you're going to be some kind of database administrator working in a buttoned-up corporate environment, those companies tend to favor SQL Server and Oracle.
Good luck. Any choice you make will probably be fine. Knowing some flavor of SQL is useful for your future endeavors.
SQL is a language like any other language but working on database. It is called SQL because it works on structured data like table (i.e rows and columns). After reading the documentation of PostgreSQL, I think we do not need any separate server installation. You can download it from here. If you are facing any issues with it I suggest using MySQL workbench. Although installation may take longer time, but its easy to understand.

Is my SQL version determined by the database I'm accessing or by my SQL client?

I have a SQL query I want to optimize, so I asked the database owner what version of SQL they were using (since ordinary methods didn't seem to have support). They answered that my version of SQL is not decided by them but by my local SQL client. They claimed to use a system called "DB2", with support for multiple SQL dialects.
I then went on to ask our IT department which version of SQL our client was using (that client being Squirrel SQL). After some fiddling around they logged on to the database, queried it and reported the version of SQL to be DB2.[sequence of decimals].
This is probably a stupid question, but would someone mind clarifying this?
Is the version of SQL I'm using determined by the database I'm accessing or by my SQL client?
If the version of SQL is decided by the database, then which version of SQL is DB2 associated with? Does it use its own version?
"They answered that my version of SQL is not decided by them but by my local SQL client"
That's complete and utter nonsense - those people apparently have no idea what they are talking about.
The SQL dialect that is understood by the server is only defined by that server. The client has absolutely nothing to do with that. If the database server doesn't support some specific feature, no SQL client will change that.
There is an industry standard called ANSI SQL that database vendors implement. Then on top of that they tack on non-standard proprietary stuff, extra commands, keywords, procedural stuff like stored procedures and triggers and cursors, that are not covered by a standard but which they expect will provide useful features that will differentiate them from the competition.
For Db2 11’s compliance with standards see https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.common.doc/doc/c0011215.html. The actual spec is behind a paywall so this is not that helpful. See https://www.whoishostingthis.com/resources/ansi-sql-standards/#sql-ansi-standards-for-database-administration for an explanation of ANSI SQL standards.
Different db2 products (Z/OS, LUW) might have different extensions. Z/OS has to do horrible mainframey stuff that LUW can do without. But you wouldn’t be given a choice, you have to use the commands implemented by the database that you are connected to. The SQL client doesn’t have a role in this.

Does MSSQL currently have any features similar to "PERIOD" columns in SQL2011?

I have a project where the PERIOD columns defined in the SQL2011 spec are the perfect solution. Unfortunately, I am forced to use MSSQL 2008R2 (or possibly MSSQL 2012) as my database, which does not support this feature.
Is there any proprietary feature that resembles the PERIOD features in SQL2011 currently in MSSQL? If not, any advice for the best way to try to implement something resembling it?
Take a look at Anchor Modelling. I know it's not exactly what you're looking for, (a PERIOD equivalent) but databases implemented as an Anchor model can include bi-temporal aspects. The generated SQL code when exporting the model primarily supports MS SQL. Oracle is available too but a lot of work when into optimizing the schema, trigger and view SQL code for MS SQL. Maybe it'll help, maybe you can see how they implemented bi-temporal data in a way that works really well with MS SQL.

Which RDBMS has the richest super-set of ANSI-SQL?

Back in 1989, when I used to program with Oracle 5.2.3 on UNIX and VAX/VMS platforms, I considered SQLPLUS as having the richest super-set of built-in functions. ORACLEFORMS also had the ability to embed SQL statements within triggers. That was then, 21 years ago. At present, which other RDBMS' have come close, have the same, or more functionality than Oracle's SQLPLUS, DB2?.. SQL-Server?.. T-SQL?.. MySQL?.. etc?
It's hard to tell what is "richest". All systems have some proprietary things which the other systems don't support, including, but not limited to:
MODEL clause in Oracle
CROSS APPLY in SQL Server
DISTINCT ON in PostgreSQL
ON DUPLICATE KEY UPDATE in MySQL
DB2 has a complete Java virtual machine available for server side processing stored procedures, you don't get much more "complete" than that.
CouchDB uses JavaScript, can't get much more flexible and complete that that either.

Vendor neutral SQL

I'm currently working on a project for a web application that may be installed on several different servers with various software configurations. I want to make my application as flexible as possible by allowing the user to have various SQL servers installed. The problem is the SQL syntax used by any two server vendors does not match up. For a simple example, here is the same SELECT statement for MS SQL and MySQL:
MS SQL - SELECT TOP 1 * FROM MyTable ORDER BY DateCreated DESC
MySQL - SELECT * FROM MyTable ORDER BY DateCreated DESC LIMIT 1
Are there any standard way to abstract the statement creation for various vendors? Any online resources or books discussing this problem? Any hints or smart-alec remarks that I'd find useful?
Further information: I'm writing my we application in vanilla ASP running on a Windows server.
Thanks, Spara
You can conform to ANSI SQL 92. All major RDBMS I know will support that.
However, there are tons of things individual RDBMS makers have added to enhance their own flavor of SQL. That is where you get into a lurch.
You may have to branch out in code depending on the RDBMS you are connecting to and generate / choose the appropriate SQL statement at that point.
A better option would be to create a DAL for each supported RDBMS. Implement a DAL interface across the DALs to make them uniform. This should be easier than switching in code.
I suggest that instead of trying to please everybody, you should write your code such that you support the top one or two systems that you expect to deploy on, and add support for other RDBMS as and when required.
I suggest you use an ORM (linq, nhibernate etc) to abstract the SQL dialect away rather than trying to write plain vanilla SQL.
Edit: Is there an OR/M for Classic ASP?
You know, I bet you could get by with strictly ansi sql, it will just take some effort and probably extra work. i.e.
SELECT MAX(*) FROM mytable ORDER BY datecreated DESC;
There will be workarounds in ansi because really all of the db specific constructs are ways to shorten and or shortcut existing ways of getting at or describing data. Another option might be to restrict access to the various databases to stored procs and user-defined functions. That way, you could write scripts for a bunch of the dbs you know will be used with the requirement that your db specific script be run before the app will work.
Just an idea.