def sql_create_table(savFilename):
    """Generate SQL 'CREATE TABLE' statement on the basis of <savFilename>
    SPSS-to-SQL datatype translation:
    numeric, except date/time --> FLOAT
    date or time --> CHAR(26) (iso dates where applicable)
    string < 256 bytes --> CHAR of that length
    string >= 256 bytes --> TEXT
    $sysmis --> NULL
    """
    varNames, varTypes, formats = get_metadata(savFilename)
    tbl = get_table_name(savFilename)
    # if "id" happens to be an existing varname, then suffix the primary key
    suffix = "_%04d" % random.randint(1000, 9999) if "id" in varNames else ""
    sql = "CREATE TABLE %(tbl)s (id%(suffix)s COUNTER PRIMARY KEY,\n  "
    sql = [sql % locals()]
    for varName in varNames:
        varType = varTypes[varName]
        format_ = formats[varName].lower()
        dataType = "FLOAT" if varType == 0 else \
                   "CHAR(%d)" % varType if varType < 256 else "TEXT"
        dataType = "CHAR(26)" if "time" in format_ or \
                   "date" in format_ else dataType
        sql.append("%(varName)s %(dataType)s, \n  " % locals())
    return "".join(sql).rstrip(", \n  ") + "\n);"
Generate SQL 'CREATE TABLE' statement on the basis of <savFilename>
    SPSS-to-SQL datatype translation:
    numeric, except date/time --> FLOAT
    date or time --> CHAR(26) (iso dates where applicable)
    string < 256 bytes --> CHAR of that length
    string >= 256 bytes --> TEXT
    $sysmis --> NULL
    
recipes/Python/578826_sav2mdb/recipe-578826.py