Changes between Version 3 and Version 4 of REDCap sql fields


Ignore:
Timestamp:
01/29/14 15:45:58 (10 years ago)
Author:
Nick Holden
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • REDCap sql fields

    v3 v4  
    4646value VARCHAR(100),
    4747label VARCHAR(100),
    48 INDEX 'reference' ('project','form','field'),
    49 KEY 'value_key' ('project','form','field','value'),
    50 KEY 'label_key' ('project','form','field','label'),
    51 FOREIGN KEY ('project') REFERENCES redcap_projects (project_name)
    52   ON UPDATE CASCADE,
     48INDEX reference (project,form,field),
     49KEY value_key (project,form,field,value),
     50KEY label_key (project,form,field,label)
    5351);
    5452}}}
     
    6462But I think you can only use a foreign key if the corresponding column holds unique values, and that isn't true for the form name or field name columns in redcap_metadata - fields and forms only have to be unique within a particular project, not across the whole database. So maybe we can't have foreign keys for all three.
    6563
     64And foreign keys cause all sorts of MySQL errors unless the columns are identical in hidden ways. Easier for the time being not to use them.
     65
    6666Need to check with the REDCap data model. I've asked for more information. In the meantime the above would work, but in a limited way, with no updating for field or form names.
    6767
     
    7373
    7474Of course, sometimes you want to use the same list more than once. In this case, the form and field names in the database should relate to the question which makes FIRST use of the list.
     75
     76=== Loading data into the table ===
     77
     78If you have more than a couple of  elements to add, use LOAD DATA LOCAL INFILE. This isn't entirely straightforward.
     79
     80Prepare the text file. Match up the columns and populate with the correct project, form and field names. Save it from excel as 'tab delimited text' (comma separated doesn't work because there are commas in the text. Then open it in an editor and remove any / all quote marks. Now upload to the server.
     81
     82Firstly, because it represents a security risk, you have to enable local loading, by starting your mysql client connection with the option " --local-infile".
     83
     84Secondly, from within mysql connection, do something like:
     85
     86{{{
     87LOAD DATA LOCAL INFILE '/home/nick/sql_insert_medications.txt' INTO TABLE sql_fields
     88FIELDS TERMINATED BY '\t'
     89LINES TERMINATED BY '\n'
     90(id,project,form,field,value,label)
     91;
     92}}}
     93