Sybase SQL Anywhere to MariaDB Migration

SQLines tools can help you transfer data, convert database schema (DDL), views, stored procedures, functions, triggers, queries and SQL scripts from SAP SQL Anywhere, Sybase SQL Anywhere, Sybase Adaptive Server Anywhere (Sybase ASA) to MariaDB.

Databases:

  • Sybase SQL Anywhere 17, 16, 12, 11, 10, 9 and 5
  • MariaDB 11.x, 10.x and 5.x

See also Sybase Adaptive Server Enterprise to MariaDB Migration.

Migration Reference

SQL Language Elements

Converting SQL language elements and constructs:

Sybase SQL Anywhere MariaDB
1 IF condition THEN exp ELSE exp2 ENDIF IF expression IF(condition, exp, exp2)

Data Types

Character data types:

Sybase SQL Anywhere MariaDB
1 CHAR(n) Variable-length string, not padded, 1 ⇐ n ⇐ 32767 CHAR(n⇐255) TEXT
2 LONG VARCHAR Character data, ⇐ 2G LONGTEXT

Unicode data:

Sybase SQL Anywhere MariaDB
1 LONG NVARCHAR Variable-length UTF-8 string, ⇐ 2G LONGTEXT
2 NCHAR(n) Fixed-length UTF-8 string, 1 ⇐ n ⇐ 32,767 NCHAR(n)
3 NVARCHAR(n) Variable-length UTF-8 string, 1 ⇐ n ⇐ 32767 NVARCHAR(n)

Numeric data types:

Sybase SQL Anywhere MariaDB
1 BIGINT 64-bit integer BIGINT
2 DECIMAL(p,s) Fixed point number DECIMAL(p,s)
3 DOUBLE [PRECISION] Double-precision floating-point number DOUBLE [PRECISION]
4 INTEGER, INT 32-bit integer INTEGER, INT
5 NUMERIC(p,s) Fixed point number NUMERIC(p,s)
6 SMALLINT 16-bit integer SMALLINT

Date and time data types:

Sybase SQL Anywhere MariaDB
1 DATE Date (year, month and day) DATE
2 DATETIME Date and time with fraction (microseconds) DATETIME(6)
3 TIME Time (hour, minute, second and microseconds fraction) TIME(6)
4 TIMESTAMP Date and time with fraction (microseconds) DATETIME(6)

Binary data:

Sybase SQL Anywhere MariaDB
1 LONG BINARY Binary data, ⇐ 2G LONGBLOB

Built-in SQL Functions

String functions:

Sybase ASA MariaDB
1 CONVERT(CHAR[(len)], exp) Convert to string CONVERT(exp, CHAR[(len)]) Different parameter
order
CONVERT(VARCHAR[(len)], exp) VARCHAR cannot be used
2 LOCATE(str, substr [,pos]) Get position of substring,
pos can be negative
LOCATE(substr, str [,pos]) Different parameter
order, no negative pos
INSTR(str, substr) The same parameter order
3 REPEAT(string, n) Repeat string n times REPEAT(string, n)
4 REPLICATE(string, n) Repeat string n times REPEAT(string, n)
5 UCASE(string) Uppercase string UCASE(string)

Date and time functions:

Sybase ASA MariaDB
1 CURRENT TIMESTAMP Get the current date and time CURRENT_TIMESTAMP(6)
CURRENT_TIMESTAMP
2 DATEADD(year, n, exp) Add n years TIMESTAMPADD(year, n, exp)
DATEADD(quarter, n, exp) Add n quarters TIMESTAMPADD(quarter, n, exp)
DATEADD(month, n, exp) Add n months TIMESTAMPADD(month, n, exp)
DATEADD(week, n, exp) Add n weeks TIMESTAMPADD(week, n, exp)
DATEADD(day, n, exp) Add n days TIMESTAMPADD(day, n, exp)
DATEADD(dayofyear, n, exp) Add n days TIMESTAMPADD(day, n, exp)
DATEADD(hour, n, exp) Add n hours TIMESTAMPADD(hour, n, exp)
DATEADD(minute, n, exp) Add n minutes TIMESTAMPADD(minute, n, exp)
DATEADD(second, n, exp) Add n seconds TIMESTAMPADD(second, n, exp)
DATEADD(millisecond, n, exp) Add n milliseconds TIMESTAMPADD(millisecond, n, exp)
DATEADD(microsecond, n, exp) Add n microseconds TIMESTAMPADD(microsecond, n, exp)
3 DATENAME(year | yy, exp) Year (1-9999) YEAR(exp)
DATENAME(Quarter | qq, exp) Quarter (1-4) QUARTER(exp)
DATENAME(Month | mm, exp) Month (January - December) MONTHNAME(exp)
DATENAME(Week | wk, exp) Week (1-54), begins on Sunday WEEK(exp)
DATENAME(Day | dd, exp) Day of month (1-31) DAY(exp)
DATENAME(Dayofyear | dy, exp) Day of year (1-366) DAYOFYEAR(exp)
DATENAME(Weekday | dw, exp) Day of week (Monday-Sunday) DAYNAME(exp)
DATENAME(Calyearofweek | cyr, exp) Year of week start YEAR(exp)
DATENAME(Calweekofyear | cwk, exp) Week (1-53) WEEK(exp)
DATENAME(Caldayofweek | cdw, exp) Day of week (1-7), Monday = 1 DAYOFWEEK(exp)
DATENAME(Hour | hh, exp) Hour (0-23) HOUR(exp)
DATENAME(Minute | mi, exp) Minute (0-59) MINUTE(exp)
DATENAME(Second | ss, exp) Second (0-59) SECOND(exp)
DATENAME(Millisecond | ms, exp) Millisecond (0-999) MICROSECOND(exp)/1000
DATENAME(Microsecond | mcs, exp) Microsecond (0-999999) MICROSECOND(exp)
DATENAME(TZOffset | tz, exp) Time zone
4 DAYS(dt1, dt2) Datetime difference in days TIMESTAMPDIFF(DAY, dt1, dt2)
5 MONTHS(dt1, dt2) Datetime difference in months TIMESTAMPDIFF(MONTH, dt1, dt2)
6 SECONDS(dt1, dt2) Datetime difference in seconds TIMESTAMPDIFF(SECOND, dt1, dt2)

System functions:

Sybase ASA MariaDB
1 CURRENT USER Get the authenticated user name CURRENT_USER
CURRENT_USER

CREATE FUNCTION Statement

Converting user-defined SQL functions:

Sybase SQL Anywhere MariaDB
1 CREATE FUNCTION name CREATE FUNCTION name
2 (IN param type DEFAULT default, …) (param type, …) Default is not supported
3 RETURNS datatype(length) RETURNS datatype(length)

CREATE PROCEDURE Statement

Converting stored procedures:

Sybase SQL Anywhere MariaDB
1 CREATE [OR REPLACE] PROCEDURE name CREATE [OR REPLACE] PROCEDURE name
2 (IN | OUT | INOUT param type DEFAULT default, …) (IN | OUT | INOUT param type, …) Default is not supported

CREATE TABLE Statement

Converting table definitions:

Sybase SQL Anywhere MariaDB
1 DEFAULT TIMESTAMP Auto-updated timestamp DEFAULT CURRENT_TIMESTAMP(6)
ON UPDATE CURRENT_TIMESTAMP(6)
2 DEFAULT LAST USER User modified row DEFAULT CURRENT_USER

Data type attributes:

Sybase SQL Anywhere MariaDB
1 UNSIGNED integer_type Non-negative integer integer_type UNSIGNED
2 INLINE num Data type attribute Removed
3 PREFIX num Data type attribute Removed

Constraints:

Sybase SQL Anywhere MariaDB
1 PRIMARY KEY(col [ASC | DESC], …) Primary key PRIMARY KEY(col [ASC | DESC], …)

Foreign keys:

Sybase SQL Anywhere MariaDB
1 NOT NULL FOREIGN KEY NULLs are not allowed FOREIGN KEY NOT NULL clause commented
2 FOREIGN KEY (col ASC | DESC, …) Column ordering Not supported for foreign keys, removed

Transact-SQL Statements

Converting T-SQL statements from Sybase ASA to MariaDB:

Sybase SQL Anywhere MariaDB
1 DECLARE name EXCEPTION
FOR SQLSTATE [VALUE] val
User-defined exception DECLARE name CONDITION
FOR SQLSTATE [VALUE] val
SQLSTATE values are different

Exception block:

Sybase SQL Anywhere MariaDB
1 BEGIN
declarations
statements
EXCEPTION
WHEN condition THEN exception_stmts
END
BEGIN
declarations
DECLARE EXIT HANDLER
FOR condition BEGIN exception_stmts END
statements
END
EXIT HANDLER must be defined
after variable declarations

Error Codes

Converting error codes from Sybase ASA to MariaDB:

Sybase SQL Anywhere MariaDB
1 SQLSTATE '52003' Name of the column could not be found SQLSTATE '42S22' Unknown column '%s' in '%s'