How to add reference to database by code

Hello! I’m trying to understand how reference fields work and how I can add them into my database using code.

From what I’ve read, a reference field is a field that’s used to point to a different row of a data in a different database. What this will do is it will link one row of data in one database with another row of data in another database.

  1. Can reference fields be used to display data like normal? Or are they there purely for referencing purposes? (eg. I have a database whose primary field contains emails, after I’ve referenced my 2nd database to this one, can I use the reference field in my 2nd database to display these emails?)

  2. What’s the difference between replaceReferences() and insertReference()? I assume “insert” would create a new row with the reference, while “replace” would act similar to the update() function.

  3. How do I properly use those 2 functions? I tried using them, and all I got was an error saying something along the lines of “This field is not a multi-reference field.”, even though I’ve set my field to be reference. Does “multi-” have something to do with it?

Thanks in advance.