Skip to content
Advertisement

From sqlite syntax to mysql syntax

I’m having some troubles moving from sqlite syntax to mysql syntax. Does anybody know a ressource showing the basic syntax in sqlite and its equivalent in mysql ?

In my particular case, I want to transform this sqlite code into mysql one:

For the moment, I did that:

DROP TABLE IF EXISTS post;

But I got errors with CURRENT_TIMESTAMP() and TEXT.

Any help would be highly appreciated.

Advertisement

Answer

Actually the only change that you have to do is to use AUTO_INCREMENT instead of SQLite’s AUTOINCREMENT keyword and your statement will work fine in MySql too.
See the demo.

But you’d better not use MySql’s TEXT data type.
SQLite has only 1 data type for storing strings and this is the TEXT data type.
On the other hand MySql supports VARCHAR and CHAR data types for storing string values.
If a column does not hold really long strings, then the preferred data type is VARCHAR and not TEXT.
You can find more about the differences of the 2 data types in these threads:

So a statement that would make sense is:

You may replace the number 10 in VARCHAR(10) with max expected length for each of the columns.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement