class MsSqlServerDatabaseMeta extends BaseDatabaseMeta implements IDatabase {

    @Override
    public String getFieldDefinition(IValueMeta v, String tk, String pk, boolean useAutoinc,
                                     boolean addFieldname, boolean addCr) {
        String retval = "";

        String fieldname = v.getName();
        int length = v.getLength();
        int precision = v.getPrecision();

        if (addFieldname) {
            retval += fieldname + " ";
        }

        int type = v.getType();
        switch (type) {
            case IValueMeta.TYPE_TIMESTAMP:
            case IValueMeta.TYPE_DATE:
                retval += "DATETIME";
                break;
            case IValueMeta.TYPE_BOOLEAN:
                if (supportsBooleanDataType()) {
                    retval += "BIT";
                } else {
                    retval += "CHAR(1)";
                }
                break;
            case IValueMeta.TYPE_NUMBER:
            case IValueMeta.TYPE_INTEGER:
            case IValueMeta.TYPE_BIGNUMBER:
                if (fieldname.equalsIgnoreCase(tk) || // Technical key
                        fieldname.equalsIgnoreCase(pk) // Primary key
                ) {
                    if (useAutoinc) {
                        retval += "BIGINT PRIMARY KEY IDENTITY(0,1)";
                    } else {
                        retval += "BIGINT PRIMARY KEY";
                    }
                } else {
                    if (precision == 0) {
                        if (length > 18) {
                            retval += "DECIMAL(" + length + ",0)";
                        } else {
                            if (length > 9) {
                                retval += "BIGINT";
                            } else {
                                retval += "INT";
                            }
                        }
                    } else {
                        if (precision > 0 && length > 0) {
                            retval += "DECIMAL(" + length + "," + precision + ")";
                        } else {
                            retval += "FLOAT(53)";
                        }
                    }
                }
                break;
            case IValueMeta.TYPE_STRING:
                if (length < getMaxVARCHARLength()) {
                    // Maybe use some default DB String length in case length<=0
                    if (length > 0) {
                        retval += "VARCHAR(" + length + ")";
                    } else {
                        retval += "VARCHAR(100)";
                    }
                } else {
                    retval += "TEXT"; // Up to 2bilion characters.
                }
                break;
            case IValueMeta.TYPE_BINARY:
                retval += "VARBINARY(MAX)";
                break;
            default:
                retval += " UNKNOWN";
                break;
        }

        if (addCr) {
            retval += Const.CR;
        }

        return retval;
    }

}