I'm using mysql for a while. I think to switch pdo, and want to use standard function. Can you provide non-standard syntax in mysql?
First think LIMIT in oracle they use rowcount, and mssql they use TOP .
Is this the question you are looking for:
There are a method to paging using ANSI SQL only?
Related
I must make an exponentiation of a number and I don't know which function to use between POW() and POWER(). Which of the two functions is better?
Looking at the MySQL documentation I saw that they are synonymous, but I wanted to understand if there was a reason for two functions that do the same thing.
POWER is the synonym of POW. So nothing is better, it is the same:
POWER(X,Y)
This is a synonym for POW().
Using two different names for the same function gives you the possibility to port an SQL query from one dialect to an other dialect without (big) changes.
An example:
You want to use the following TSQL query on MySQL too:
SELECT POWER(2,2) -- 4
Now you can write these query specific for the dialects:
SELECT POWER(2,2) -- 4 - TSQL (POW is not available on TSQL)
SELECT POW(2,2) -- 4 - MySQL
But you can also use the POWER function on MySQL since this is a synonym for POW:
SELECT POWER(2,2) -- 4 - TSQL and MySQL
pow and power are synonyms in MySQL.
I'd use power since it's part of the ANSI SQL standard and using it would make your code easier to port if you ever decide to use a different database.
Is there any equivalent command in Informix for MySQL's 'Replace' ? I'm just finding references to the string manipulation function.
Thanks!
Modern versions of Informix (11.70, 12.10) support the MERGE statement which, I think, can do the job that MySQL REPLACE does. It might require some care coding it correctly.
Is there any way to use T-SQL queries with MySQL database, like having a data connector that understand TSQL and can connect to MySQL?
Short answer, no.
By the time you've developed or found an interface that could translate T-SQL syntax into MySQL (correctly); you might as well have learnt the syntax required to write the MySQL you need.
It's not all that different to be honest; and it will broaden your knowledge and make you flexible for other types of database query languages.
Pardon my noob question but was wondering how to change the database context within mysql? I know in SQL Server, it's:
USE [DBName];
so is there an equivalent in mysql?
In MySQL, if you want to change databases, you will also use use:
mysql> use DNNAME;
Same thing: use [database]; (the ; is optional here)
MySQL 5.0 Reference Manual :: 13.8.4 USE Syntax
The use command switches databases in MySQL. The following line
`use [database];`
will switch between databases, where you substitute the actual name of your database for [database], like use db1;.
Are there any SQL Validators that can check syntax against multiple database servers?
For example, I might want to check whether a particular query will work against Oracle, MySQL and SQL Server.
I am more concerned about the SQL syntax than the actual schema being queried, so a tool that can catch major syntax errors, like detecting that the limit clause is not supported in SQL Server and Oracle would be good enough.
EDIT:
Several answers have suggested checking syntax for a particular DBMS or for ANSI Standard.
What I am looking for a possibility of targeting a sort of union of features between two or more databases (say SQL Server and Oracle). I would like to be able to use any SQL feature that is supported by all of the DBMS I am targeting in a particular application.
I am not sure if it is worthwhile. I think it depends upon the number of non-ANSI features shared by several databases. If there are very few, then perhaps it will be better to target the ANSI standard.
I'm not aware of any that are that specific, these will check that the statements are valid ansi 92/99/2003...
http://developer.mimer.com/validator/index.htm
That will get you 99% of the way there (especially if are only doing CRUD operations)
maybe if you know which reserved words are used by which database you could roll your own simple checker..
see : How to find if a column name is a reserved keyword across various databases
(as already mentioned) If your goal is to create a database agnostic system think about using a third party tool e.g: entityspaces
For the MySQL: try automatic SQL syntax check feature in dbForge Studio for MySQL.
For the Oracle: PL/SQL Editor in dbForge Studio for Oracle
This is an online mysql syntax checker, but this is mysql only
http://www.piliapp.com/mysql-syntax-check/
You can use https://www.db-fiddle.com/. It supports the following DBs
MySQL 8.0
MySQL 5.7
MySQL 5.6
MySQL 5.5
PostgreSQL 13
PostgreSQL 12
PostgreSQL 11
PostgreSQL 10.0
PostgreSQL 9.6
PostgreSQL 9.5
PostgreSQL 9.4
SQLite 3.30
SQLite 3.26