Add/attach a field to all content types
Use your favourite SQL client and amnually populate {field_config_instance} table:


In Drupal, create field in one content type.
In your favourite editor create set of 39 queries (40 content types minus that one you worked out manually), with the same field values. Just leave id empty so autoincrement can work, and populate entity_type with your conetnt type names. I use spreadsheets to do that, first spreadsheet column is first query part, second is for the names of content types (obtained by querying {node_type}, third is for last part of the query.
Paste that query set into your SQL client and execute.