0

Thanks to some organizational oddities, my work team now has somewhat limited access to a random database, but we're not entirely sure what syntax we should be using with it. In an ideal world, we'd like it to be MySQL.

Can anyone describe or point me toward a set of table-creation and selection queries that will allow us to test whether this is MySQL? Ideally, this set of queries will be something that works only on MySQL, throwing an error on other systems.

4 Answers 4

4

Try running the MySQL select version command:

 SELECT VERSION()

http://dev.mysql.com/doc/refman/5.0/en/installation-version.html

Does it have to be a table creation and/or selection query or will the above work?

Sign up to request clarification or add additional context in comments.

2 Comments

That statement would work with Postgres as well. Obviously it would return something different ;)
I'm pretty sure this is a good answer, but in our case, it looks like maybe we don't have the privileges/capability necessary on application layer to run the function; the rather opaque application layer through which we are forced to run our commands returns a syntax error. My guess is that it can only run a subset of SELECT statements. I guess that in itself answers the question to some extent, in that we now know we're not dealing with a full set of SQL syntax options. That gives you "accepted answer" status, in my book.
1

You can test your DDL statements on sqlfiddle and then, run them on MySQL, which should take care of most of your SQL issues. Alternatively, use hibernate or a similar ORM and don't worry about SQL at all.

1 Comment

I appreciate the suggestions. They don't apply in our case, since we have limited access to the system involved, but I hope someone will find them helpful.
1

Each RDBMS has their respective protocol and client library. The client of one RDBMS generally won't work to connect to the wrong brand of RDBMS.

I would suggest you test connecting using the MySQL client. If that doesn't work, it isn't MySQL. :-)


Re comments:

MySQL does not restrict syntax based on privileges, so you should never get a syntax error. And you can call most builtin functions even if you have no privileges to access any databases or tables. I confirmed this:

mysql> grant usage on *.* to 'dummy'@'%';  /* minimal privilege */

$ mysql -udummy

mysql> select version();
+-----------------+
| version()       |
+-----------------+
| 5.5.31-30.3-log |
+-----------------+

If you got a syntax error on that statement, I would say you're actually connected to a different RDBMS that doesn't have a VERSION() function.

For example, Microsoft SQL Server has a @@VERSION global variable, and they have the SERVERPROPERTY() function that you can use to query the server version and other information. (See links for documentation.)

In my experience, sites that use Microsoft SQL Server seldom call it Microsoft SQL Server, they mistakenly call it "SQL" or even "MySQL". So my first guess is that you're using that product. Use the global variable and function I mention above to test this.

Comments

0
select * from v$version;

This could work, but I'm not sure if this is specific to MySQL let alone if it even works in MySQL - I thought I'd share. Let us know if it works!

4 Comments

Just curious: Why the downvote? I haven't tried his yet, but I'm hoping that maybe the downvoter can give us extra explanation of why he/she considers this a bad idea. That might add significantly to the conversation. There are lots of really good answers on here (one of which will be accepted once I've tried some of them out), but if I'm splitting hairs, this is probably the only response that attempts to answer the original question as phrased. Unless it can be shown to be somehow dangerous or ends up completely failing, I'm inclined to lean toward it by default as an accepted answer.
I appreciate your feedback. I'm not sure why I got a downvote either - although the other answers seem good as well, I don't think mine was unconstructive or irrelevant in any way. After doing some Googling, though, I think this query is meant for Oracle. I hope that (somehow) mine, or one of the others, was able to help you out and figure out what you were looking for. :)
I appreciate your honesty about this being Oracle. While that Oracle caveat (combined with the effectiveness of Chad Cook's answer) forced me to give Chad "accepted" status, I've voted your suggestion back up.
@eternalnewb I appreciate it very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.