Skip to content

T-SQL compatibility ​

FbExpert translates SQL Server objects to Firebird: functions, types, catalog views, procedures and triggers. This page summarizes what is covered and what is not.

T-SQL to Firebird translation
Source analysis, expression rewriting, TSQL_COMPAT library, trial compilation.

Three mechanisms ​

MechanismPurpose
Native rewritingreplaces an expression with its Firebird equivalent (GETDATE() → CURRENT_TIMESTAMP)
TSQL_COMPAT packagePSQL functions installed in the target database when a translation depends on them
MSSQL_SCHEMA viewsreplace INFORMATION_SCHEMA and sys.* (Firebird 6 reserves INFORMATION_SCHEMA)

The TSQL_COMPAT package is created only if a translated object uses it. Its version is tracked (TSQL_COMPAT 1.5 today) and it is reinstalled automatically during a rebuild.

Common functions ​

T-SQLFirebird
GETDATE(), SYSDATETIME()CURRENT_TIMESTAMP
NEWID()GEN_UUID()
ISNULL(a, b)COALESCE(a, b)
LEN(x)CHAR_LENGTH(TRIM(TRAILING FROM x))
CHARINDEX(n, h)POSITION(n IN h)
SUBSTRING(x, s, l)SUBSTRING(x FROM s FOR l)
LEFT / RIGHTcomputed SUBSTRING(...)
DATEADD / DATEDIFFDATEADD(n part TO d) / DATEDIFF(part FROM a TO b)
DATEPART(p, d)EXTRACT(p FROM d)
IIF(c, a, b)CASE WHEN c THEN a ELSE b END
a % bMOD(a, b)
CONVERT(varchar, d, style)TSQL_COMPAT.CONVERT_DATE(style, d)

Date units ​

year/yy/yyyy, quarter/qq/q, month/mm/m, day/dd/d, dayofyear/dy/y, week/wk/ww, weekday/dw/w, hour/hh, minute/mi/n, second/ss/s, millisecond/ms are accepted.

YEARDAY and WEEKDAY are not valid units for DATEADD/DATEDIFF in Firebird: these cases must still be handled manually and the object is flagged during compilation.

Types ​

T-SQLFirebird
int, bigint, smallint, tinyintINTEGER, BIGINT, SMALLINT
bitBOOLEAN
decimal, numericNUMERIC(p,s)
moneyNUMERIC(19,4)
float / realDOUBLE PRECISION / FLOAT
varchar(max)VARCHAR(8191) in an expression, BLOB SUB_TYPE TEXT in a column
text, ntext, xmlBLOB SUB_TYPE TEXT
image, varbinary(max)BLOB SUB_TYPE BINARY
datetime, datetime2TIMESTAMP
uniqueidentifierUUID (CHAR_TO_UUID from text)
timestamp, rowversionBIGINT

Compatibility views ​

INFORMATION_SCHEMA.* and sys.* references are rewritten to MSSQL_SCHEMA.*:

SQL ServerFirebird
INFORMATION_SCHEMA.TABLES / COLUMNS / VIEWSMSSQL_SCHEMA.TABLES / COLUMNS / VIEWS
INFORMATION_SCHEMA.TABLE_CONSTRAINTSMSSQL_SCHEMA.TABLE_CONSTRAINTS
INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTSMSSQL_SCHEMA.REFERENTIAL_CONSTRAINTS
INFORMATION_SCHEMA.ROUTINESMSSQL_SCHEMA.ROUTINES
sys.objects / tables / columnsMSSQL_SCHEMA.SYS_OBJECTS / SYS_TABLES / SYS_COLUMNS
sys.indexes / index_columnsMSSQL_SCHEMA.INDEXES / INDEX_COLUMNS
sys.triggersMSSQL_SCHEMA.SYS_TRIGGERS
sys.sql_expression_dependenciesMSSQL_SCHEMA.SYS_SQL_EXPRESSION_DEPENDENCIES

A view is created only if an object references it. OBJECT_ID identifiers are unique per type: relations unchanged, procedures +1,000,000, functions +2,000,000, triggers +3,000,000 — that is the space used by MSSQL_SCHEMA.SYS_OBJECTS.

VIEWS does not contain VIEW_DEFINITION, CHECK_OPTION or IS_UPDATABLE. TABLE_CONSTRAINTS excludes NOT NULL constraints.

Not covered ​

These functions are not translated: the object remains a skeleton marked FBEXPERT_NOT_TRANSLATED, with the original T-SQL body kept as a comment, and the workshop flags it.

INDEXPROPERTY, PATINDEX, STUFF, REPLICATE, SPACE, QUOTENAME, FORMAT, STR, TRY_CAST, TRY_CONVERT, PARSE, STRING_AGG, DATEFROMPARTS, EOMONTH, SWITCHOFFSET, TODATETIMEOFFSET, SCOPE_IDENTITY, DB_ID, USER_NAME, HOST_NAME, CHECKSUM, NEWSEQUENTIALID, ERROR_*, @@TRANCOUNT, MERGE, FOR XML.

A skeleton is never presented as a success: it stays visible, exportable and editable manually.

Checking a translation ​

  1. start the analysis in the workshop (external source or DDL script);
  2. read the statuses: translated, skeleton, failed;
  3. compile a trial: compilation detects missing references before anything is written;
  4. test sensitive objects on a staging database.

Full reference

The exhaustive table of functions, views and maintenance rules is maintained in the package's technical documents (docs/tsql-compatibility-functions.md, docs/tsql-compatibility-views.md).